Tuesday, 29 April 2014

Thread in C#

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace OnlyOneInstance
{
static class Program
{
[STAThread]
static void Main()
{
bool instantiated;
/* If instantiated is true, this is the first instance of the application; else, another instance is running. */
Mutex mutex = new Mutex(true, "UniqueID", out instantiated);
if (!instantiated)
{
MessageBox.Show("Already Running");
return;
}
Application.Run(new Form1());
GC.KeepAlive(mutex);
}
}
}