using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; namespace TouchCashier { /// /// App.xaml 的交互逻辑 /// public partial class App : Application { System.Threading.Mutex mutex; public App() { DispatcherUnhandledException += App_DispatcherUnhandledException; //非UI线程未捕获异常处理事件 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Startup += new StartupEventHandler(App_Startup); } /// /// UI线程异常处理事件 /// /// /// void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { //MessageBox.Show(e.Exception.ToString()); //Shutdown(1); try { LogHelper.WriteServiceLog($"主线程错误:{e.Exception.Message}"); } catch { } e.Handled = true; } /// /// 非UI线程异常处理事件 /// /// /// void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { //Loger.WriteErrorLog("捕获未处理异常:" + e.ExceptionObject); try { LogHelper.WriteServiceLog("子线程错误:"+(e.ExceptionObject as Exception).Message); } catch { } //MessageBox.Show(e.ExceptionObject.ToString()); } /// /// 程序启动处理 /// /// /// void App_Startup(object sender, StartupEventArgs e) { bool ret; mutex = new System.Threading.Mutex(true, "TouchCashier", out ret); if (!ret) { //ActivateOtherWindow(); //MessageBox.Show("Program has started, you can't start again!"); Environment.Exit(0); } else { MainWindow _MainWindow = new MainWindow(); _MainWindow.Show(); } } } }