class OneAtATimePlease
{
static void Main()
{
using (var mutex = new Mutex(false, "oreilly.com OneAtATimeDemo"))
{
if (mutex.WaitOne(TimeSpan.FromSeconds(3), false))
RunProgram();
else
{
Console.WriteLine("Another instance of the app is running. Bye!");
return;
}
}
}
static void RunProgram()
{
Console.WriteLine("Running. Press Enter to exit");
Console.ReadLine();
}
}
但是这些行等待有人调用Set()
函数:
if (mutex.WaitOne(TimeSpan.FromSeconds(3), false))
RunProgram();
谁set
在这儿打电话?这个线程永远不会被释放......(或者会?)
我错过了什么?