Controle one application from another

  • Thread starter Thread starter Fredrik Andersson
  • Start date Start date
F

Fredrik Andersson

Hi

I have a problem, I need to controle one app from another application. If I
press a button in app1 then somthing is going to happend in app2.

I hope somone understands what I mean.

Thanks
- Fredrik
 
Fredrik said:
I have a problem, I need to controle one app from another application. If I
press a button in app1 then somthing is going to happend in app2.

I think remoting will be right for you. If you decide to do so, follow
these instructions:

1.

Create a interface, that contains all the methods that app2 shoud be
able to do.

2.

In app2, declare these using's and this object:

using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;

....

private IChannel channel1 = null;

At the time, where the application should start "listening" to commands,
insert about this code (customize port number and service name):

channel1 = new TcpChannel(12345);
ChannelServices.RegisterChannel(channel1);
RemotingServices.Marshal(this,"MyApp2.rem");

3.

In app1, simply add this code (again, change port number and service
name as you did above, and the name of the interface (IYourInterface)):

string strConnectionString = "tcp://" + Host + ":12345/MyApp2.rem";
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel);

IYourInterface x =
(IYourInterface)Activator.GetObject(typeof(IYourInterface),strConnectionString);
if (x==null)
{
// something went wrong
}
else
{
// call any methods here
}

May be in your case it's clever to define "x" (please use a good name
for this object) at class level, run the activation at start up of your
application and in the button's click event, check whether x is null or
not and do the things you want.

HTH,

Michael
 
Hi,

You may need to define a protocol to send commands to the target
application. if you give more details a better solution can be proposed.


cheers,
 
Thanks Michael

Is there no posibility to do app2 as a com object in some way. It's just a
fiew of the functions i need to use and I know that both of them will be on
the same computer
 
Back
Top