Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In .NET what's the best way for two processes in the same machine to communicate?

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 :)

like image 323
cruizer Avatar asked Jan 22 '09 08:01

cruizer


1 Answers

Named pipes are usually best but also consider MSMQ for a fire and forget scenario that ensures message delivery over time. It really depends on your message sizes as well. TCP would become tricky because you'd need a unique port per user.

like image 61
DarkwingDuck Avatar answered Oct 12 '22 23:10

DarkwingDuck