第十三章 -------------------WPF应用程序实现单例

发布时间 2023-11-17 10:41:48作者: 程序员的夏天

public partial class App : Application
{
System.Threading.Mutex mutex;
public App()
{
this.Startup += new StartupEventHandler(App_Startup);
}
void App_Startup(object sender, StartupEventArgs e)
{
bool ret;
mutex = new System.Threading.Mutex(true, "ElectronicNeedleTherapySystem", out ret);

if (!ret)
{
MessageBox.Show("已经启动请先关闭之后再打开!");
Environment.Exit(0);
}

}
}