share int value between two or more process using C#?
I would like to share int counter between two process and base on some logic int value will be incremented.
can any one suggest me a way to do it using .Net 3.5 framework?
Thanks Krishna
If you only need to incremenet the counter from different threads, take a look at the Interlocked.Increment method
To communicate between processes you could use WCF (Windows Communication Foundation) with a Named Pipe Binding.
From the link above:
A named pipe is an object in the Windows operating system kernel, such as a section of shared memory that processes can use for communication. A named pipe has a name, and can be used for one-way or duplex communication between processes on a single machine.
When communication is required between different WCF applications on a single computer, and you want to prevent any communication from another machine, then use the named pipes transport. An additional restriction is that processes running from Windows Remote Desktop may be restricted to the same Windows Remote Desktop session unless they have elevated privileges.
Use Memory mapped files or System.IO.Pipes
, See below.
- What's the easiest way to communicate between two processes in C#?
Memory mapped files is introduced in .Net Framework 4.0. Otherwise, you can use Named Pipes.
Look into the Inter-Process Data Exchange. Here's the good article about it.
精彩评论