views:

60

answers:

4

I have an app that, when launched, checks for duplicate processes of itself.

That part I have right - but what I need is to check a state variable in the original running process in order to run some logic.

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

+1  A: 

The easiest: Create a file, and write something in it.

More advanced, and when done correctly more robust, is using WCF, you use named pipes to setup some communication channel on the local computer only.

GvS
+1  A: 

If you're using a Mutex to check whether another process is running (you should be) you could use another Mutex whose locked state would be the boolean flag you're looking.

Paul Sasik
A: 

The standard way of doing this is to use the Windows API to create and lock a mutex. The first app to open will create and lock the mutex. Any subsequent executions of the app will not be able to get it and can then shutdown.

Sarge
+4  A: 

There are a bunch of ways to do this. A very primative way would be to read/write from a file. The old win32 way would be to use PostMessage. The more .NET way would be to use remoting or WCF and Named Pipes.

.NET 4 is also getting support for Memory Mapped files.

Here is a pretty thorough looking artcile describing a few different approaches including support for Memory Mapped files outside of .NET 4 http://www.codeproject.com/KB/threads/csthreadmsg.aspx

Bob