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);

                }
            }

        }

 

posted on 2019-01-28 11:44  legion  阅读(262)  评论(0编辑  收藏  举报

导航