多线程09-Mutex
class Program
{
static void Main()
{
const string MutexName = "CSharpThreadingCookbook";
using (var m = new Mutex(false, MutexName))
{
if (!m.WaitOne(TimeSpan.FromSeconds(5)))
{
Console.WriteLine("second instance is runing");
}
else
{
Console.WriteLine("Runing");
Console.ReadKey();
m.ReleaseMutex();
}
}
}
}
{
static void Main()
{
const string MutexName = "CSharpThreadingCookbook";
using (var m = new Mutex(false, MutexName))
{
if (!m.WaitOne(TimeSpan.FromSeconds(5)))
{
Console.WriteLine("second instance is runing");
}
else
{
Console.WriteLine("Runing");
Console.ReadKey();
m.ReleaseMutex();
}
}
}
}