[問題] Mutex在Release Build失效
請教高手:
以下代碼在Debug Build是可行的,但在Release Build下Mutex無效,
第二個instance仍然會產生是什麼原因?
static class Program
{
[STAThread]
static void Main()
{
bool flag = false;
System.Threading.Mutex mutex = new System.Threading.Mutex(true,
"My_Mutex", out flag);
if (flag)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
MessageBox.Show("Only one instance allowed to run at a time",
"Error !", MessageBoxButtons.OK, MessageBoxIcon.Warning);
System.Threading.Thread.Sleep(5000);
Environment.Exit(1);
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.220.36.133
推
12/30 19:05, , 1F
12/30 19:05, 1F
→
12/30 19:05, , 2F
12/30 19:05, 2F
推
12/30 21:55, , 3F
12/30 21:55, 3F
推
12/30 21:59, , 4F
12/30 21:59, 4F
推
12/30 22:08, , 5F
12/30 22:08, 5F
推
12/30 22:13, , 6F
12/30 22:13, 6F
→
12/30 22:38, , 7F
12/30 22:38, 7F
→
12/30 22:42, , 8F
12/30 22:42, 8F
→
12/30 22:45, , 9F
12/30 22:45, 9F
推
12/30 22:58, , 10F
12/30 22:58, 10F
→
12/30 22:58, , 11F
12/30 22:58, 11F
→
12/30 23:11, , 12F
12/30 23:11, 12F
→
12/30 23:11, , 13F
12/30 23:11, 13F
推
12/31 04:45, , 14F
12/31 04:45, 14F
推
12/31 05:00, , 15F
12/31 05:00, 15F
→
12/31 05:01, , 16F
12/31 05:01, 16F
→
01/02 00:06, , 17F
01/02 00:06, 17F
→
01/02 00:07, , 18F
01/02 00:07, 18F