how to create a mutex that would ensure there is only one
instance of the application running at any point.??
thank you!! :)
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Apr 17, 2013, 11:29 AM
using System;
using System.Threading;
class Program
{
static void Main()
{
// create Mutex with a 'unique' name
Mutex m = new Mutex(false, "Raps Gao Single Instance App");
// give any existing instance a chance to shutdown
if (!m.WaitOne(TimeSpan.FromSeconds(2), false))
{
Console.WriteLine("There is already an existing instance running");
}
else
{
Run();
}
m.Dispose();
}
static void Run()
{
Console.WriteLine("Program is running - please any key to close down");
Console.ReadKey(true);
}
}