Exemple #1
0
        /// <summary> 只创建一个实例 </summary>
        public void UseSingleInstance()
        {
            //Process thisProc = Process.GetCurrentProcess();

            //var p = Process.GetProcessesByName(thisProc.ProcessName);

            //if (p.Length > 1)
            //{
            //    MessageWindow.ShowSumit("当前程序已经运行!");

            //    this.Shutdown();
            //}

            Process thisProc = Process.GetCurrentProcess();

            //互斥量创建成功标志
            bool createdNew;

            //创建互斥量
            mutex = new Mutex(true, thisProc.ProcessName, out createdNew);

            if (!createdNew)
            {
                MessageWindow.ShowSumit("当前程序已经运行!");

                Application.Current.Shutdown();
            }
        }
Exemple #2
0
        void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            Current.Dispatcher.Invoke(() => MessageWindow.ShowSumit(e.Exception.Message, "系统异常", 5));

            e.Handled = true;

            this.ILogger?.Error("系统异常");
            this.ILogger?.Error(e.Exception);
        }
        /// <summary> 只创建一个实例 </summary>
        public void UseSingleInstance()
        {
            Process thisProc = Process.GetCurrentProcess();

            var p = Process.GetProcessesByName(thisProc.ProcessName);

            if (p.Length > 1)
            {
                MessageWindow.ShowSumit("当前程序已经运行!");

                this.Shutdown();
            }
        }
Exemple #4
0
        /// <summary> 异步线程抛出没有补货的异常 </summary>
        private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            foreach (Exception item in e.Exception.InnerExceptions)
            {
                sb.AppendLine($@"异常类型:{item.GetType()}
异常内容:{item.Message}
来自:{item.Source}
{item.StackTrace}");
            }

            e.SetObserved();

            this.ILogger?.Error("Task Exception");
            this.ILogger?.Error(sb.ToString());

            Current.Dispatcher.Invoke(() => MessageWindow.ShowSumit(sb.ToString(), "系统任务异常", false, 5));
        }