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?

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.