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

 

posted @ 2014-01-15 13:02  guosongORxiaosong  阅读(241)  评论(0编辑  收藏  举报