【WPF】只允许运行一个程序(单例)

https://blog.csdn.net/shikong_/article/details/77047235

 

App.xaml.cs 文件:

     namespace ElectronicNeedleTherapySystem  
    {  
        /// <summary>  
        /// App.xaml 的交互逻辑  
        /// </summary>  
        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);  
                }  
      
            }  
        }  
    }  

 

【WPF】只允许运行一个程序(单例)

上一篇:Windows server 2012 安装exchange 2013


下一篇:EXSI启用本地登录和SSH服务连接功能,使用Xshell连接