zoukankan      html  css  js  c++  java
  • C# Winform 禁止一个进程运行多次

    禁止一个进程运行多次

    using System;
    using System.Windows.Forms;
    
    namespace StartExe
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
    
                bool ret;
                System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out ret);
                if (ret)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                    //   Main   为你程序的主窗体,如果是控制台程序不用这句   
                    mutex.ReleaseMutex();
                }
                else
                {
                    //MessageBox.Show(null, "有一个和本程序相同的应用程序已经在运行,请不要同时运行多个本程序。
    
    这个程序即将退出。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //   提示信息,可以删除。   
                    Application.Exit();//退出程序  
                }
            }
        }
    }
    

      

  • 相关阅读:
    对于git的认识
    第一篇博客
    结对编程
    对git的认识
    李叔同先生的《梦》
    51nod 1449 砝码称重
    LeetCode 21-29题解
    LeetCode 11-20题解
    LeetCode 6-10 题解
    LeetCode刷题重启博客
  • 原文地址:https://www.cnblogs.com/YYkun/p/11459585.html
Copyright © 2011-2022 走看看