WPF 设置程序不允许同一类程序多开进程

315
补充展位 Pages_Weblog_Get#0
文章摘要
此内容由人工摘要内容,并由AI根据文章内容进行润色
暂无内容

WPF 设置程序只能开启唯一一个进程 不允许多开

修改App.xaml.cs 代码 添加如下代码即可实现

private static System.Threading.Mutex IMutex;
protected override void OnStartup(StartupEventArgs e)
 {
     string MyAppID="OnlyRun_App";//运行进程互斥标识名称 可自行修改
     IMutex= new System.Threading.Mutex(true, MyAppID);
     if (IMutex.WaitOne(0, false))
     {
           ///正常启动程序
           base.OnStartup(e);
     }else{
          MessageBox.Show("程序已经在运行!", "提示",MessageBoxButton.OK,MessageBoxImage.Asterisk);
          this.Shutdown();//已存在运行进程 执行关闭
     }
}
补充展位
Pages_Weblog_Get#d836b369-e8a9-486c-8a7e-6f7610c8d969
补充展位 Pages_Weblog_Get#1
补充展位 Pages_Weblog_Get#2
专题推荐
暂无内容
补充展位 Pages_Weblog_Get#3