C# 使用Mutex只有一个进程

使用Mutex只有一个进程

代码

        static void Main()
        {
            bool createdNew;
            using(Mutex mutex=new Mutex(true,Application.ProductName,out createdNew))
            {
                if (createdNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
                else
                {
                    MessageBox.Show("Only One Instance is allowed");
                    System.Environment.Exit(1);

                }
            }

        }

猜你喜欢

转载自www.cnblogs.com/legion/p/10329586.html