Search code examples
c#winformssingle-instance

How to prevent open my application more than one time?


Possible Duplicate:
What is the correct way to create a single instance application?

How can I define my application to open only one time after click on its exe file over and over?


Solution

  • I've always done this at the application's entry point:

    bool onlyInstance = false;
    
    Mutex m = new Mutex(true, "MyUniqueMutextName", out onlyInstance);
    if (!onlyInstance)
    {
        return;
    }
    
    GC.KeepAlive(m);