【问题标题】:check multiple instance availabiliy with mutiple mutex?使用多个互斥体检查多个实例的可用性?
【发布时间】: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#


    【解决方案1】:
     Mutex m = new System.Threading.Mutex(true, "asa", out ok);
     Mutex m = new System.Threading.Mutex(true, "ASDA", out ok);
    

    他们都需要相同的名字

     Mutex m = new System.Threading.Mutex(true, "ASDA", out ok);
    

    应该是

     Mutex m = new System.Threading.Mutex(true, "asa", out ok);
                                                  ^-------------------Change
    

    【讨论】:

    • 在这个名字都一样,
    • 所有键的唯一性不同,但这没有运行请检查我的代码,由于安全原因,我已经更改了它的名称
    • 您遇到了什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多