I have two exe running, C# console programs. From one, I need to tell the second exe to do something? How can I do this? I looked at
(Remotable.CommonAssembly)Activator.GetObject(typeof(Remotable.CommonAssembly)
but from here I can call a method of the CommonAssembly(referenced dll) not the exe one's.
For simple scenarios a plain old windows event would be enough - a program waits to be signaled to do something.
Spawn a thread in the waiting program that waits for the event.
//Program 1
EventWaitHandle evt = OpenOrCreateEvent("Global\\MyEvent");
evt.WaitOne(); // this thread will block waiting without wasting CPU cycles,
// it will be be signaled from the kernel
// when the event is set
DoStuff();
//Program 2
EventWaitHandle evt = OpenOrCreateEvent("Global\\MyEvent");
evt.Set();
Take a look at the EventWaitHandle, ManualResetEvent, AutoResetEvent classes.
Advanced IPC mechanisms like WCF, Remoting, DCOM, CORBA, etc may be better if you have more complicated communication protocol with different actions to trigger, return values and so on. For simple cases (a couple) of windows events would be enough.
Notice If you need to transfer data between your processes consider memory mapped files. "Official" .NET classes for them will be available with .NET 4.0, currently you can use http://github.com/tomasr/filemap/tree/master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With