WPF单例运行
程序员文章站
2022-07-13 22:31:31
...
在App.xaml中使用mutex:
private Mutex mutex = new Mutex(true, "My Singleton Instance");
protected override void OnStartup(StartupEventArgs e)
{
//单例
if (mutex.WaitOne(TimeSpan.Zero, true))
{
base.OnStartup(e);
}
else
{
Shutdown();
}
}