Are we alone?

Simple way to make sure there is only one instance of your application running in the window session. If you need there to be only one instance on the machine, change 'Local' to 'Global'.

static void Main()
{
    using (Mutex m = new Mutex(true, @"Local\" + Application.ProductName))
    {
        if (m.WaitOne(0, true))
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Program());
        }
    }
}

Google
m@kli.dk @klinkby RSS feed  GitHub