Пример #1
0
        //static void Main()
        //{
        //    Application.EnableVisualStyles();
        //    Application.SetCompatibleTextRenderingDefault(false);
        //    //Thread.Sleep(5000);
        //    Application.Run(new RuChuKuForm());
        //}
        static void Main()
        {
            bool noRun = false;

            Run = new System.Threading.Mutex(true, "HumControl", out noRun);
            //检测是否已经运行
            if (noRun)//未运行
            {
                try
                {
                    Run.ReleaseMutex();
                    Application.ThreadException += new ThreadExceptionEventHandler(UIThreadException);
                    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                    AppDomain.CurrentDomain.UnhandledException +=
                        new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);


                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    sysLog.WriteAnyString("---------------------------------------------------------------------------------");
                    sysLog.WriteDebug("系统开始启动!");
                    Application.Run(new RuChuKuForm());
                }
                catch
                {
                    Application.Restart();
                }
            }
            else//已经运行
            {
                //MessageBox.Show("系统正在运行\r\n请不要重复开启!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //MessageBox.Show("已经有一个实例正在运行!");
                //切换到已打开的实例
            }
        }