Skip to content

Commit eaac72b

Browse files
committed
Handle TaskSchedulerUnhandledException
1 parent 6b9c9e9 commit eaac72b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Flow.Launcher/App.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
153153

154154
RegisterAppDomainExceptions();
155155
RegisterDispatcherUnhandledException();
156+
RegisterTaskSchedulerUnhandledException();
156157

157158
var imageLoadertask = ImageLoader.InitializeAsync();
158159

@@ -284,6 +285,15 @@ private static void RegisterAppDomainExceptions()
284285
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
285286
}
286287

288+
/// <summary>
289+
/// let exception throw as normal is better for Debug
290+
/// </summary>
291+
[Conditional("RELEASE")]
292+
private static void RegisterTaskSchedulerUnhandledException()
293+
{
294+
TaskScheduler.UnobservedTaskException += ErrorReporting.TaskSchedulerUnobservedTaskException;
295+
}
296+
287297
#endregion
288298

289299
#region IDisposable

Flow.Launcher/Helper/ErrorReporting.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using System.Windows.Threading;
34
using NLog;
45
using Flow.Launcher.Infrastructure;
@@ -30,6 +31,14 @@ public static void DispatcherUnhandledException(object sender, DispatcherUnhandl
3031
e.Handled = true;
3132
}
3233

34+
public static void TaskSchedulerUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
35+
{
36+
//handle unobserved task exceptions
37+
Report(e.Exception);
38+
//prevent application exist, so the user can copy prompted error info
39+
e.SetObserved();
40+
}
41+
3342
public static string RuntimeInfo()
3443
{
3544
var info =

0 commit comments

Comments
 (0)