IPC Mechanisms in C# - Usage and Best Practices

C#.NetIpc

C# Problem Overview


I have used IPC in Win32 code a while ago - critical sections, events, and semaphores.

How is the scene in the .NET environment? Are there any tutorial explaining all available options and when to use and why?

C# Solutions


Solution 1 - C#

Most recent Microsoft's stuff in IPC is Windows Communication Foundation. Actually there is nothing new in the lower level (tcp, upd, named pipes etc) But WCF simplifies IPC development greatly.

Useful resource:

and of course MSDN on WCF

Solution 2 - C#

Apart from the obvious (WCF), there is a ZeroMQ binding for C#/CLR which is pretty good:

http://www.zeromq.org/bindings:clr

Does message-oriented IPC, pub/sub and various other strategies with much less code and config than WCF.

It's also at least an order of magnitude faster than anything else and has less latency if you require low latency comms.

With respects to semaphores, locks, mutexes etc. If you share by communicating rather than communicate by sharing, you'll have a whole load less hassle than the traditional paradigm.

Solution 3 - C#

I tend to use named pipes or Unix sockets (depending on whether I'm targetting MS.NET or Mono -- I have a class that abstracts it away) since it's easy to use, portable, and allows me to easily interoperate with unmanaged code. That said, if you're only dealing with managed code, go with WCF or remoting -- the latter if you need Mono support, since their WCF support simply isn't there yet.

Solution 4 - C#

I would recommend using Memory Mapped Files if you need to use on the machine domain not communication through network. See the following link.

http://techmikael.blogspot.com/2010/02/blazing-fast-ipc-in-net-4-wcf-vs.html

Solution 5 - C#

There is also .NET Remoting, which I found quite cool, but I guess they are obsoleting it now that they have WCF.

Solution 6 - C#

It sounds as though you're interested in synchronization techniques rather than communication. If so, you might like to start here, or perhaps this more concise overview.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionprakashView Question on Stackoverflow
Solution 1 - C#akuView Answer on Stackoverflow
Solution 2 - C#DeletedView Answer on Stackoverflow
Solution 3 - C#Serafina BrociousView Answer on Stackoverflow
Solution 4 - C#DemirView Answer on Stackoverflow
Solution 5 - C#ibzView Answer on Stackoverflow
Solution 6 - C#Kent BoogaartView Answer on Stackoverflow