What is the easiest way to do inter process communication in C#?

27,921

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

Share:
27,921
Admin
Author by

Admin

Updated on December 29, 2020

Comments

  • Admin
    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
    Bobby over 14 years
    Actually, 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
    Groo over 14 years
    I 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
    Zonus almost 9 years
    Very simple; easy, etc... By far the easiest from what I'm seeing.
  • Hien Nguyen
    Hien Nguyen about 5 years
    please provide solution without external library
  • Legends
    Legends over 4 years
    Only for .NET framework apps, no support in .NET Core