C# 单例模式实现

2021/11/6 17:12:02

本文主要是介绍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;
            }

 



这篇关于C# 单例模式实现的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程