zoukankan      html  css  js  c++  java
  • 让应用程序单例方式运行

                                         让应用程序单例方式运行

                                            周银辉

    小经验,做个笔记:

        public partial class App : Application
        {
            
    public App()
            {
                
    //不一定要是在Startup时,请选择适合自己应用程序的合理时间
                Startup += AppStartup;
            }

            
    void AppStartup(object sender, StartupEventArgs e)
            {
                
    bool createNew;
                var mutex 
    = new Mutex(true"TheIdOfThisMutex"out createNew);

                
    if (!createNew)
                {
                    MessageBox.Show(
    "another instance is running");
                    
    //记得在关闭程序前关闭mutex,否则进程有可能不退出
                    mutex.Close();
                    
    //不一定要调用Shutdown方法,请选择适合自己应用程序的退出方式
                    Shutdown();
                }
                
    else
                {
                    
    //记得正常退出程序是关闭mutex
                    Exit += delegate{ mutex.Close(); };
                }
            }
        }
  • 相关阅读:
    C++学习之路: share_from_this<T>类的使用
    Linux学习: TCP粘包问题
    C++学习之路: 线程封装(基于对象编程)
    js数组方法
    React 性能优化
    HelloWorld
    设置表格边框的通用写法
    用于项目的SQL写法
    添加服务,用于定期执行某个程序或者应用程序(windows service)
    sql中除法,保留小数点位数
  • 原文地址:https://www.cnblogs.com/zhouyinhui/p/1587246.html
Copyright © 2011-2022 走看看