Single Instance

  • Thread starter Thread starter Shawn
  • Start date Start date
You can use a Mutex for this.

example:

using System;
using System.Windows.Forms;
using System.Threading;

class WinApp : Form
{
static void Main()
{
bool firstInstance;
Mutex m = new Mutex(true, "unique_name_here", out firstInstance);

if(firstInstance)
{
Application.Run(new WinApp());
}
else
{
MessageBox.Show("already running!");
}

}
}


Regards, Mikael
 
Create a named ManualResetEvent and try to obtain it with a timeout of
zero. If it is not set then set it. The next instance will try to do the
same but will see that the event is signaled. It should then exit
immediatelly.
 
Back
Top