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

 

posted @ 2021-11-06 15:27  码农界的小学生  阅读(94)  评论(0编辑  收藏  举报