C#进程间的同步,实现只能运行一个程序的效果

using System;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool createdNew;
            using (new Mutex(true,Application.ProductName,out createdNew))
            {
                if (createdNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
                else
                {
                    // todo:提示程序已启动
                }
            }
        }
    }
}
原文地址:https://www.cnblogs.com/yao2yao4/p/3124945.html