只能运行一个程序,禁止运行多个相同的程序 C#

原文发布时间为:2009-04-06 —— 来源于本人的百度文章 [由搬家工具导入]

Program.cs 里面改成如下:

static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool bExist;
            System.Threading.Mutex MyMutex = new System.Threading.Mutex(true, "OnlyRunOncetime", out

bExist);
            if (bExist)
            {
                Application.Run(new Form1());
                MyMutex.ReleaseMutex();
            }
            else
            {
                MessageBox.Show("程序已经运行!", "信息提示", MessageBoxButtons.OK,

MessageBoxIcon.Information);
            }
        }

原文地址:https://www.cnblogs.com/handboy/p/7153278.html