What’s the best (or maybe not the best — just good) way for two processes in the same machine to communicate, using .NET?
Actually the two processes in the app I’m working on aren’t even two different programs; they’re just two instances of the same EXE. I wanted to do something like a singleton app, but have it per user (meaning a Terminal Server or Citrix or App-V server with multiple users should be able to launch their own single copy of the app). If another instance is run by the same user, it should just delegate the task to the already running instance, then exit. Only one instance per user of the program should be running. So far I’ve done (thanks to StackOverflow) the part that detects whether an instance of the app is already running, using Mutex. But I need the second app instance to be able to send data to the first app instance.
I’m leaning towards using named pipes and WCF’s NetNamedPipeBinding for this, but if you have better ideas I’ll really appreciate it. Thanks 🙂
I would go for Named Pipes.
Basically, you’ll need a unique endpoint per user. As with your Mutex, you’ll probably use the username to find out the name of the named pipe to use. This might even replace your use of the Mutex: try to find out if a named pipe for this particular already exists, and if it does, it means you’re the second instance to run.
It’s harder to map a TCP port onto a user.
Oh, and by using Named Pipes, I’m actually saying ‘Remoting over Named Pipes’.