zoukankan      html  css  js  c++  java
  • 禁止WinForm程序开启多次

    static Mutex vMyMutex;

    static void Main

    {

    bool vF;
                vMyMutex = new Mutex(true, "Transactions", out vF);   // xxxxxx 是自己取的名稱
                if (!vF)
                {                                                                   // 表示已經有同名的 Mutex
                    vMyMutex.Close();
                    vMyMutex = null;
                    MessageBox.Show("该程式已开启,不可以开启多个相同的程式.", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                Application.ApplicationExit += OnApplicationExit;

    }

    static void OnApplicationExit(object sender, EventArgs e)
            {
                if (vMyMutex != null)
                {

                    try
                    {
                        vMyMutex.ReleaseMutex();// 釋放 Mutex
                        vMyMutex.Close();
                    }
                    catch (Exception ex)
                    {
                        MyLog vMyLog = new MyLog();
                        vMyLog.WriteLog(ex.Message);
                    }
                }
            }

            public static void ApplicationExit()
            {
                for (int i = 0; i < vFormArrayList.Count; i++)
                {
                    ((Form)vFormArrayList[i]).Close();
                }
                Application.DoEvents();
                Application.ExitThread();
            }

  • 相关阅读:
    字符串删减
    iOS-AFNetworking与ASIHTTPRequest的区别
    iOS-清理缓存
    iOS-addSubView时给UIView添加效果
    iOS-明杰解决字段冲突,及数组映射
    iOS-开发将文本复制到剪切板
    iOS-加载html字符串
    iOS-UILabel加线
    iOS-获取webView的高度
    iOS-plist文件的写读
  • 原文地址:https://www.cnblogs.com/jacker1979/p/1689626.html
Copyright © 2011-2022 走看看