Fredrik Andersson wrote:
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(IYourIn terface),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
--
http://www.mkcs.at/
The specified e-mail-address is valid and will be read.