@@ -32,6 +32,7 @@ public App()
32
32
this . Exit += this . App_Exit ;
33
33
34
34
this . DispatcherUnhandledException += this . App_DispatcherUnhandledException ;
35
+ TaskScheduler . UnobservedTaskException += this . TaskScheduler_UnobservedTaskException ;
35
36
AppDomain . CurrentDomain . UnhandledException += this . CurrentDomain_UnhandledException ;
36
37
}
37
38
@@ -95,6 +96,14 @@ private void CloseServer()
95
96
private void App_DispatcherUnhandledException (
96
97
object sender ,
97
98
DispatcherUnhandledExceptionEventArgs e )
99
+ {
100
+ e . Handled = true ;
101
+ this . DumpUnhandledException ( e . Exception ) ;
102
+ }
103
+
104
+ private void TaskScheduler_UnobservedTaskException (
105
+ object sender ,
106
+ UnobservedTaskExceptionEventArgs e )
98
107
{
99
108
this . DumpUnhandledException ( e . Exception ) ;
100
109
}
@@ -106,30 +115,27 @@ private void CurrentDomain_UnhandledException(
106
115
this . DumpUnhandledException ( e . ExceptionObject as Exception ) ;
107
116
}
108
117
109
- private async void DumpUnhandledException (
118
+ private void DumpUnhandledException (
110
119
Exception ex )
111
120
{
112
- await Task . Run ( ( ) =>
121
+ if ( ! Directory . Exists ( Config . AppData ) )
113
122
{
114
- if ( ! Directory . Exists ( Config . AppData ) )
115
- {
116
- Directory . CreateDirectory ( Config . AppData ) ;
117
- }
118
-
119
- File . WriteAllText (
120
- Path . Combine ( Config . AppData , @".\CeVIOAIProxy.error.log" ) ,
121
- $ "{ DateTime . Now : yyyy-MM-dd HH:mm:ss.fff} \n { ex } ",
122
- new UTF8Encoding ( false ) ) ;
123
- } ) ;
123
+ Directory . CreateDirectory ( Config . AppData ) ;
124
+ }
124
125
126
+ File . WriteAllText (
127
+ Path . Combine ( Config . AppData , @".\CeVIOAIProxy.error.log" ) ,
128
+ $ "{ DateTime . Now : yyyy-MM-dd HH:mm:ss.fff} \n { ex } ",
129
+ new UTF8Encoding ( false ) ) ;
125
130
this . CloseServer ( ) ;
131
+
126
132
CeVIOAIProxy . MainWindow . Instance ? . HideNotifyIcon ( ) ;
127
133
Config . Instance . Save ( ) ;
128
134
129
135
MessageBox . Show (
130
136
"予期しない例外を検知しました。アプリケーションを終了します。\n \n " +
131
137
ex ,
132
- "Fatal" ,
138
+ "Fatal - CeVIO AI Proxy " ,
133
139
MessageBoxButton . OK ,
134
140
MessageBoxImage . Error ) ;
135
141
0 commit comments