What is the easiest way to do inter process communication in C#?
Solution 1
The easiest and most reliable way is almost certainly IpcChannel (a.k.a. Inter Process Communication Channel); that's what it's there for. You can get it up and running with a couple of lines of code and configuration.
Solution 2
You can try .NET Remoting. Here is a simple example: CodeProject .NET Remoting.
If you are using .NET 3.5, you should go for WCF, as Remoting is slowly becoming obsolete. Again, there are many examples for WCF around.
Solution 3
I've created my own open source library for quick and easy IPC which works between Windows services, console applications and Windows forms.
It has some advantages over existing IPC implementations and doesn't require any configuration.
See here.
Solution 4
For completeness, you can also to use net.pipe
and WCF
.
Solution 5
Another way would be to imitate a named pipe. Declare a file somewhere, and read from/write to it.
Or, if the programs get executed in sequence, you could try the clipboard...but that solution is ugly as hell and is buggy (sometimes .NET can't access the clipboard for no reason).
Admin
Updated on December 29, 2020Comments
-
Admin over 3 years
I have two C# applications and I want one of them send two integers to the other one (this doesn't have to be fast since it's invoked only once every few seconds).
What's the easiest way to do this? (It doesn't have to be the most elegant one.)
-
Bobby over 14 yearsActually, as far as I remember, you can specify from which addresses to accept connections (or at least check from what address it is coming, and if it is not localhost...well, never talk to strangers ;) ).
-
Groo over 14 yearsI strongly disagree with the clipboard part. And I see no point in imitating a named pipe, when you can simply use actual named pipes?
-
Zonus almost 9 yearsVery simple; easy, etc... By far the easiest from what I'm seeing.
-
Hien Nguyen about 5 yearsplease provide solution without external library
-
Legends over 4 yearsOnly for .NET framework apps, no support in .NET Core