views:

126

answers:

2

I have multiple instances of the same Windows Forms .net 3.5 SP1 C# application running on the same machine.

Now I'd like to be able to communicate with them from .net, one instance at a time. What's the most simplest way to do this?

I read a bit about WCF, but I have only found examples working with one server and one client. But in my case all running instances would be a server and I need to discuss with just one of them.

I imagine something like this:

Process[] procs = Process.GetProcessesByName("ProcessName");
foreach (Process p in procs)
{
  // Communicate with process here
}
A: 

The simple thing is database :) , btw WCF support peer to peer communication with NetPeerTcpBinding

Anton Setiawan
+2  A: 

You'll need some kind of subscribe/callback mechanism. Don't loop through the projects, but have each application subscribe to a wcf service method instead.

Example: http://idunno.org/archive/2008/05/29/wcf-callbacks-a-beginners-guide.aspx

Gerrie Schenck
@Gerrie Schenck: That's a good idea. However this means that I still need 1 separate process of which I'm sure it's started only once. Ideally I would have liked to do all within the same application.
Marc
Then you probably won't need WCF, but simply a controller with events on which the forms can subscribe.
Gerrie Schenck
@Gerrie Schenck: OK but how should this be done? Each process would have its own controller so there wouldn't be any inter-process communication. I think I'll try to go with your suggestion and implement a separate process which works as server. So each time a process starts it will try to subscribe to the server process and if this one isn't available it will start a new one and register afterwards.
Marc