mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3627 from Flow-Launcher/task_exception
Silent handle TaskSchedulerUnobservedTaskException
This commit is contained in:
commit
dae84aef16
1 changed files with 6 additions and 4 deletions
|
|
@ -1,20 +1,21 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using Flow.Launcher.Infrastructure;
|
using Flow.Launcher.Infrastructure;
|
||||||
using Flow.Launcher.Infrastructure.Exception;
|
using Flow.Launcher.Infrastructure.Exception;
|
||||||
|
using Flow.Launcher.Infrastructure.Logger;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace Flow.Launcher.Helper;
|
namespace Flow.Launcher.Helper;
|
||||||
|
|
||||||
public static class ErrorReporting
|
public static class ErrorReporting
|
||||||
{
|
{
|
||||||
private static void Report(Exception e, [CallerMemberName] string methodName = "UnHandledException")
|
private static void Report(Exception e, bool silent = false, [CallerMemberName] string methodName = "UnHandledException")
|
||||||
{
|
{
|
||||||
var logger = LogManager.GetLogger(methodName);
|
var logger = LogManager.GetLogger(methodName);
|
||||||
logger.Fatal(ExceptionFormatter.FormatExcpetion(e));
|
logger.Fatal(ExceptionFormatter.FormatExcpetion(e));
|
||||||
|
if (silent) return;
|
||||||
var reportWindow = new ReportWindow(e);
|
var reportWindow = new ReportWindow(e);
|
||||||
reportWindow.Show();
|
reportWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
@ -35,8 +36,9 @@ public static class ErrorReporting
|
||||||
|
|
||||||
public static void TaskSchedulerUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
|
public static void TaskSchedulerUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
// handle unobserved task exceptions on UI thread
|
// log exception but do not handle unobserved task exceptions on UI thread
|
||||||
Application.Current.Dispatcher.Invoke(() => Report(e.Exception));
|
//Application.Current.Dispatcher.Invoke(() => Report(e.Exception, true));
|
||||||
|
Log.Exception(nameof(ErrorReporting), "Unobserved task exception occurred.", e.Exception);
|
||||||
// prevent application exit, so the user can copy the prompted error info
|
// prevent application exit, so the user can copy the prompted error info
|
||||||
e.SetObserved();
|
e.SetObserved();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue