首页 > Windows开发 > 详细

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

时间:2021-06-15 16:15:28      阅读:13      评论:0      收藏:0      [点我收藏+]

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】只允许运行一个程序(单例)

原文:https://www.cnblogs.com/Mars-0603/p/14884299.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!