Skip to content

Commit dae84ae

Browse files
authored
Merge pull request #3627 from Flow-Launcher/task_exception
Silent handle TaskSchedulerUnobservedTaskException
2 parents 9755186 + 2582a9f commit dae84ae

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Flow.Launcher/Helper/ErrorReporting.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
using System;
22
using System.Runtime.CompilerServices;
33
using System.Threading.Tasks;
4-
using System.Windows;
54
using System.Windows.Threading;
65
using Flow.Launcher.Infrastructure;
76
using Flow.Launcher.Infrastructure.Exception;
7+
using Flow.Launcher.Infrastructure.Logger;
88
using NLog;
99

1010
namespace Flow.Launcher.Helper;
1111

1212
public static class ErrorReporting
1313
{
14-
private static void Report(Exception e, [CallerMemberName] string methodName = "UnHandledException")
14+
private static void Report(Exception e, bool silent = false, [CallerMemberName] string methodName = "UnHandledException")
1515
{
1616
var logger = LogManager.GetLogger(methodName);
1717
logger.Fatal(ExceptionFormatter.FormatExcpetion(e));
18+
if (silent) return;
1819
var reportWindow = new ReportWindow(e);
1920
reportWindow.Show();
2021
}
@@ -35,8 +36,9 @@ public static void DispatcherUnhandledException(object sender, DispatcherUnhandl
3536

3637
public static void TaskSchedulerUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
3738
{
38-
// handle unobserved task exceptions on UI thread
39-
Application.Current.Dispatcher.Invoke(() => Report(e.Exception));
39+
// log exception but do not handle unobserved task exceptions on UI thread
40+
//Application.Current.Dispatcher.Invoke(() => Report(e.Exception, true));
41+
Log.Exception(nameof(ErrorReporting), "Unobserved task exception occurred.", e.Exception);
4042
// prevent application exit, so the user can copy the prompted error info
4143
e.SetObserved();
4244
}

0 commit comments

Comments
 (0)