1
1
using System ;
2
2
using System . Runtime . CompilerServices ;
3
3
using System . Threading . Tasks ;
4
- using System . Windows ;
5
4
using System . Windows . Threading ;
6
5
using Flow . Launcher . Infrastructure ;
7
6
using Flow . Launcher . Infrastructure . Exception ;
7
+ using Flow . Launcher . Infrastructure . Logger ;
8
8
using NLog ;
9
9
10
10
namespace Flow . Launcher . Helper ;
11
11
12
12
public static class ErrorReporting
13
13
{
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" )
15
15
{
16
16
var logger = LogManager . GetLogger ( methodName ) ;
17
17
logger . Fatal ( ExceptionFormatter . FormatExcpetion ( e ) ) ;
18
+ if ( silent ) return ;
18
19
var reportWindow = new ReportWindow ( e ) ;
19
20
reportWindow . Show ( ) ;
20
21
}
@@ -35,8 +36,9 @@ public static void DispatcherUnhandledException(object sender, DispatcherUnhandl
35
36
36
37
public static void TaskSchedulerUnobservedTaskException ( object sender , UnobservedTaskExceptionEventArgs e )
37
38
{
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 ) ;
40
42
// prevent application exit, so the user can copy the prompted error info
41
43
e . SetObserved ( ) ;
42
44
}
0 commit comments