protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); SettingsPath = e.Args.FirstOrDefault(); AppDomain.CurrentDomain.UnhandledException += (s, e) => LogUnhandledException((Exception)e.ExceptionObject); DispatcherUnhandledException += (s, e) => { LogUnhandledException(e.Exception); if (e.Exception is not COMException) { e.Handled = true; } }; TaskScheduler.UnobservedTaskException += (s, e) => { LogUnhandledException(e.Exception); if (e.Exception.InnerException is not COMException) { e.SetObserved(); } }; }
private void App_Startup(object sender, StartupEventArgs e) { // Hook general uncaught exception events to show user. (this won't help with some of the CLR/pinvoke errors that might occur) Dispatcher.UnhandledException += (s, e) => { e.Handled = true; ShowUnhandledException(e.Exception, "Dispatcher.UnhandledException"); }; TaskScheduler.UnobservedTaskException += (s, e) => { e.SetObserved(); ShowUnhandledException(e.Exception, "TaskScheduler.UnobservedTaskException"); }; }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var window = new MainWindow(); IIoCService iocService = new IoCService { RegisterComponents = (ioc) => { ioc.RegisterType <ESPMessageService>().As <IESPMessageService>(); } }; iocService.Build(); iocService.Resolve <IAppService>().SetTheme(ThemeType.Light); window.DataContext = iocService.Resolve <IMainWindowViewModel>(); window.Show(); iocService.Resolve <INavigationService>().NavigateTo <FindESPViewModel, FindESPView>(); AppDomain.CurrentDomain.UnhandledException += (s, e) => iocService.Resolve <IAppService>().ProcessException((Exception)e.ExceptionObject, "Domain exception"); Dispatcher.UnhandledException += (s, e) => { e.Handled = true; iocService.Resolve <IAppService>().ProcessException(e.Exception, "Dispatcher exception"); }; TaskScheduler.UnobservedTaskException += (s, e) => { if (e.Exception != null) { iocService.Resolve <IAppService>().ProcessException(e.Exception, "Unobserved exception"); e.SetObserved(); } }; }