Handle TaskSchedulerUnhandledException

This commit is contained in:
Jack251970 2025-04-12 10:52:59 +08:00
parent 6b9c9e9eb7
commit eaac72b696
2 changed files with 19 additions and 0 deletions

View file

@ -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;
}
/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private static void RegisterTaskSchedulerUnhandledException()
{
TaskScheduler.UnobservedTaskException += ErrorReporting.TaskSchedulerUnobservedTaskException;
}
#endregion
#region IDisposable

View file

@ -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 =