cross-user C# mutex

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-05-13T21:45:36Z Indexed on 2010/05/13 21:54 UTC
Read the original article Hit count: 299

Filed under:
|

My app is forced to use a 3rd party module which will blue-screen Windows if two instances are started at the same time on the same machine. To work around the issue, my C# app has a mutex:

    static Mutex mutex = new Mutex(true, "{MyApp_b9d19f99-b83e-4755-9b11-d204dbd6d096}");  

And I check if it's present - and if so I show an error message and close the app:

    bool IsAnotherInstanceRunning()
    {
        if (mutex.WaitOne(TimeSpan.Zero, true))
            return (true);
        else
            return (false);
    }

The problem is if two users can log in and open the application at the same time, and IsAnotherInstanceRunning() will return false.

How do I get around this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about mutex