using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Runtime.InteropServices; using System.Windows; namespace ConnectPoint { /// /// App.xaml 的交互逻辑 /// public partial class App : Application { [DllImport("user32", CharSet = CharSet.Unicode)] static extern IntPtr FindWindow(string cls, string win); [DllImport("user32")] static extern IntPtr SetForegroundWindow(IntPtr hWnd); [DllImport("user32")] static extern bool IsIconic(IntPtr hWnd); [DllImport("user32")] static extern bool OpenIcon(IntPtr hWnd); System.Threading.Mutex mutex; /// /// 程序入口 /// public App() { //UI线程异常处理事件 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 { ESSupport.Lib.LogHelper.WriteServiceLog($"状态反馈程序主线程异常。原因:[{e.Exception.Source}]{e.Exception.Message}"); } catch { } e.Handled = true; Environment.Exit(0); } /// /// 非UI线程异常处理事件 /// /// /// void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { try { //ESSupport.Lib.LogHelper.WriteServiceLog((e.ExceptionObject as Exception).ToString()); ESSupport.Lib.LogHelper.WriteServiceLog($"状态反馈程序子线程异常。原因:[{(e.ExceptionObject as Exception).Source}]{(e.ExceptionObject as Exception).Message}"); } catch { } } /// /// 程序启动初始化 /// /// /// void App_Startup(object sender, StartupEventArgs e) { mutex = new System.Threading.Mutex(true, "ConnectPoint", out bool ret); if (!ret) { //ActivateOtherWindow(); Environment.Exit(0); } else { MainWindow _MainWindow = new MainWindow { WindowStyle = WindowStyle.None, WindowState = WindowState.Minimized, ShowInTaskbar = false, }; _MainWindow.Show(); } } } }