C# 使用Mutex只有一个进程

Posted legion

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);

                }
            }

        }

 

以上是关于C# 使用Mutex只有一个进程的主要内容,如果未能解决你的问题,请参考以下文章