예제 #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool createdNew;

            mutex = new System.Threading.Mutex(true, Res.Resources.GetRes().GetSoftServicePCName(), out createdNew);
            System.Threading.EventWaitHandle eventWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset, Res.Resources.GetRes().GetSoftServicePCName() + Res.Resources.GetRes().GetSoftServicePCName());



            if (createdNew)
            {
                // Spawn a thread which will be waiting for our event
                var thread = new System.Threading.Thread(
                    () =>
                {
                    while (eventWaitHandle.WaitOne())
                    {
                        lock (TheLock)
                        {
                            Form defaultForm = Application.OpenForms.Cast <Form>().Where(x => null != x.Tag && x.Tag.ToString() == "Main").FirstOrDefault();

                            if (null != defaultForm)
                            {
                                defaultForm.BeginInvoke((Action)(() => BringToForeground(defaultForm)));
                            }
                        }
                    }
                });

                // It is important mark it as background otherwise it will prevent app from exiting.
                thread.IsBackground = true;

                thread.Start();

                //注册错误
                Application.ThreadException += Application_ThreadException;
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                //加载日志
                Resources.GetRes().LoadLog();
                //字体效果(为XP开启)
                FontSmoothing.OpenFontEffect();

                Resources.GetRes().SetDeviceType((long)1);
                Application.Run(new LoginWindow());
                mutex.ReleaseMutex();
            }
            // Notify other instance so it could bring itself to foreground.
            eventWaitHandle.Set();

            // Terminate this instance.
            Environment.Exit(0);
        }
예제 #2
0
        public static void Main()
        {
            bool isOwned = false;

            mutex = new System.Threading.Mutex(true, UniqueMutexName, out isOwned);
            System.Threading.EventWaitHandle eventWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset, UniqueEventName);


            if (isOwned)
            {
                // Spawn a thread which will be waiting for our event
                var thread = new System.Threading.Thread(
                    () =>
                {
                    while (eventWaitHandle.WaitOne())
                    {
                        Current.Dispatcher.BeginInvoke(
                            (Action)(() => BringToForeground()));
                    }
                });

                // It is important mark it as background otherwise it will prevent app from exiting.
                thread.IsBackground = true;

                thread.Start();

                var application = new App();
                application.InitializeComponent();

                //错误处理(UI)
                Application.Current.Dispatcher.UnhandledException += Application_DispatcherUnhandledException;
                //错误处理(非UI)
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;


                //加载日志
                Res.Resources.GetRes().LoadLog();

                // 这是平板
                Res.Resources.GetRes().SetDeviceType((long)2);

                //加载配置文件
                Config.GetConfig().GetConfigs();

                //加载屏幕
                //Screen.LoadScreenConfig();

                //隐藏任务栏
                Taskbar.Instance.Hide();

                //关闭声音
                NavigateSoundManager.Instance.DisableSound();

                //字体效果
                FontSmoothing.OpenFontEffect();


                try
                {
                    application.Run(new LoginWindow());
                }
                catch (Exception ex)
                {
                    throw ex;
                }


                return;
            }
            // Notify other instance so it could bring itself to foreground.
            eventWaitHandle.Set();

            // Terminate this instance.
            Environment.Exit(0);
        }