bool bAppExist;
System.Threading.Mutex mutex = new System.Threading.Mutex(true, "Application.ProductName", out bAppExist);
if (bAppExist)
{
mutex.WaitOne();
Console.WriteLine("Main thread waits.");
Console.ReadLine();
mutex.ReleaseMutex();
}
else
{
_pool = new Semaphore(0, 1, "Begin");
for (int i = 1; i <= 5; i++)
{
Thread t = new Thread(new ParameterizedThreadStart(Worker));
// Start the thread, passing the number.
//
t.Start(i);
}
Console.WriteLine("Main thread exits.");
_pool.Release(1);
Console.ReadLine();
}