diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 89faa105e..a9cd1a8b9 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -153,6 +153,7 @@ namespace Flow.Launcher RegisterAppDomainExceptions(); RegisterDispatcherUnhandledException(); + RegisterTaskSchedulerUnhandledException(); var imageLoadertask = ImageLoader.InitializeAsync(); @@ -284,6 +285,15 @@ namespace Flow.Launcher AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle; } + /// + /// let exception throw as normal is better for Debug + /// + [Conditional("RELEASE")] + private static void RegisterTaskSchedulerUnhandledException() + { + TaskScheduler.UnobservedTaskException += ErrorReporting.TaskSchedulerUnobservedTaskException; + } + #endregion #region IDisposable diff --git a/Flow.Launcher/Helper/ErrorReporting.cs b/Flow.Launcher/Helper/ErrorReporting.cs index 5b79c520d..1787b1d91 100644 --- a/Flow.Launcher/Helper/ErrorReporting.cs +++ b/Flow.Launcher/Helper/ErrorReporting.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using System.Windows.Threading; using NLog; using Flow.Launcher.Infrastructure; @@ -30,6 +31,14 @@ public static class ErrorReporting e.Handled = true; } + public static void TaskSchedulerUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) + { + //handle unobserved task exceptions + Report(e.Exception); + //prevent application exist, so the user can copy prompted error info + e.SetObserved(); + } + public static string RuntimeInfo() { var info =