C# 单例模式实现

c# 实现单例模式 一:

 bool runone;
 Mutex run = new Mutex(true, Application.ProductName, out runone);
        if (runone)
        {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
           Application.Run(new Form1());
        }
        else
        {
             MessageBox.Show("程序已打开");
        }

c# 实现单例模式 二:

Process[] pro = Process.GetProcessesByName(Application.ProductName);
            if (pro.Length<=1)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            else
            {
                MessageBox.Show("程序已打开");
                return;
            }
原文地址:https://www.cnblogs.com/zhengxia/p/15517102.html