C/S架构小程序在同一台服务器上禁止打开多个

static class Program
    {
        static Mutex mx;
        static bool PreventReenterProcess(string ProcessMark)
        {
            bool IsSucess;
            mx = new Mutex(true, @"Global" + ProcessMark, out IsSucess);
            if (IsSucess)
            {
                return false;   //返回false表示进程不存在。
            }
            return true;
        }

        //应用程序的主入口点
        [STAThread]
        static void Main()
        {
            string state = ConfigurationManager.AppSettings["multiple2"].ToString();
            if (PreventReenterProcess(state))
            {
                return;
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new UpdateTimeForm());
        }
    }
原文地址:https://www.cnblogs.com/guosongORxiaosong/p/3520596.html