【发布时间】:2015-03-14 10:18:04
【问题描述】:
我正在运行两个彼此并行的任务,这里我正在运行一个从他的program.cs 开始的任务,当它转到form.cs 时,我将在其中启动另一个 exe 的新应用程序。
我正在使用互斥锁来检查它的实例。我在program.cs 中使用互斥锁并添加另一个互斥锁以检查它的另一个exe 实例,但它显示已经运行.. 我将尝试用代码解释..
在第一个应用程序的程序 .cs 中
static Mutex mutex = new Mutex(true, "{sdfssdfdsf-B9A1-45fd-A8CF-72F04E6BDE8F}");
Mutex m = new System.Threading.Mutex(true, "asa", out ok);
if (!ok)
{
if (MessageBox.Show("Another Instance Is Already running of This Application", "Cyber Security", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
MessageBox.Show("System is exiting.", "Systems");
Application.ExitThread();
return;
}
}
在 Form.cs 中
static Mutex mutex = new Mutex(true, "{asdasd-B9A1-45fd-A8CF-asfsadf}");
Mutex m = new System.Threading.Mutex(true, "ASDA", out ok);
if (!ok)
{
if (MessageBox.Show("Another Instance Is Already running of This Application", "log", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
MessageBox.Show("System is exiting.", "Log");
Application.ExitThread();
return;
}
}
//but this show thee error the second instance is already ruunning?
【问题讨论】:
标签: c#