【发布时间】:2011-07-19 13:42:31
【问题描述】:
我正在尝试使用 mutex 方法只允许我的应用程序的一个实例运行。也就是说 - 我只希望一台机器上的所有用户最多有一个实例。我已经阅读了有关此问题的各种其他线程,解决方案似乎很简单,但在测试中我无法让我的第二个实例不运行。这是我的代码...
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// check that there is only one instance of the control panel running...
bool createdNew = true;
using (Mutex instanceMutex = new Mutex(true, @"Global\ControlPanel", out createdNew))
{
if (!createdNew)
{
Application.Current.Shutdown();
return;
}
}
base.OnStartup(e);
}
}
【问题讨论】: