using EC.UsingEventAggregator; using EC.Utils; using LibVLCSharp.Shared; using Prism.Ioc; using Prism.Modularity; using Prism.Unity; using System; using System.Threading.Tasks; using System.Windows; using System.Windows.Threading; namespace ECMonitor { /// /// Interaction logic for App.xaml /// public partial class App : PrismApplication { protected override void OnStartup(StartupEventArgs e) { Core.Initialize(); base.OnStartup(e); RegisterEvents(); LogFactory.GetLogger().Info("OnStartup"); // await new IpcInfoService().Test();//test sqlite } protected override Window CreateShell() { return Container.Resolve(); } protected override void RegisterTypes(IContainerRegistry containerRegistry) { } protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { moduleCatalog.AddModule(); } //protected override IModuleCatalog CreateModuleCatalog() //{ // return new ConfigurationModuleCatalog(); //} protected override void OnExit(ExitEventArgs e) { base.OnExit(e); } private void RegisterEvents() { //TaskScheduler.UnobservedTaskException += (sender, args) => //{ // MessageBox.Show(args.Exception.Message); // args.SetObserved(); //}; DispatcherUnhandledException += App_DispatcherUnhandledException; TaskScheduler.UnobservedTaskException += new EventHandler< UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { FLogger.Error("Error encountered! Please contact support." + Environment.NewLine + e.Exception.Message); e.Handled = true; } private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) { foreach (Exception item in e.Exception.InnerExceptions) { FLogger.Error(string.Format("异常类型:{0}{1}来自:{2}{3}异常内容:{4}", item.GetType(), Environment.NewLine, item.Source, Environment.NewLine, item.Message)); } //将异常标识为已经观察到 e.SetObserved(); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { FLogger.Error("Unhandled exception."); } } }