C# 使用Mutex禁止多次开启同一个程序


    class Program
    {

        //static ManualResetEventSlim MainSignaledresetEvent;
        //static ManualResetEventSlim DoWorkSignaledResetEvent;

        public static void Main()
        {
            bool firstApplictionInstance;
            string mutexName = Assembly.GetEntryAssembly().FullName;

            using (Mutex mutex = new Mutex(false, mutexName, out firstApplictionInstance))
            {
                if (!firstApplictionInstance)
                {
                    Console.WriteLine("This appliction is already running");
                    Console.ReadLine();
                }
                else

                {
                    Console.WriteLine("Enter to ShutDown");
                    Console.ReadLine();
                
                }
            
            }
        
        }
    }

```![在这里插入图片描述](https://img-blog.csdnimg.cn/20200513152655493.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p4Y3ZiMDM2,size_16,color_FFFFFF,t_70)

你可能感兴趣的:(C# 使用Mutex禁止多次开启同一个程序)