How to request a variable in another running application in C #?

I have an application that, at startup, checks for duplicate processes.

In this part, I have the right - but I need to check the state variable in the initial running process in order to start some logic.

So: how can I make a variable (e.g. bool) available to other applications so that they can request it?

+4
source share
4 answers

There are several ways to do this. A very primitive way would be to read / write from a file. The old win32 way is to use PostMessage . The more .NET there is, the better it is to use remote or WCF and Named Pipes .

.NET 4 also gets support for memory mapped files .

Here's a pretty captivating art style that describes several different approaches, including support for memory files outside of .NET 4 http://www.codeproject.com/KB/threads/csthreadmsg.aspx

+4
source

The simplest: create a file and write something in it.

More advanced, and when everything is done correctly, it uses WCF , you use named pipes to set up some communication channel on the local computer only.

+1
source

If you use Mutex to check if another process is working (you should be), you can use another Mutex whose locked state will be the boolean flag you are looking for.

+1
source

The standard way to do this is to use the Windows API to create and lock a mutex. The first application to open will create and block the mutex. Any subsequent actions of the application will not be able to receive it and then may shut down.

0
source

All Articles