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.)
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.)
I'd say make them talk over a socket.
Have one program listen
on a socket and have the other connect
to the first. Send the two integers on a single line, as strings of digits.
The only question is how they should agree on port numbers, and how they know that they're talking to one another. They can agree on port numbers by you deciding they should always use port 12345 (say), and the dirty-hacky-solution for the second part is to just trust whomever you're talking with to be a nice guy.
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).
Mutex
can be an option; please read this: Inter-Process Data Exchange using .NET 2.0
For completeness, you can also to use net.pipe
and WCF
.
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.
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.
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.