how to create a mutex that would ensure there is only one
instance of the application running at any point.??
thank you!! :)
Threading
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Apr 17, 2013, 7:29 AM EDT
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);
}
}