Skip to content

Commit d18a6b6

Browse files
committed
Merge branch 'dev'
2 parents d8cca11 + ee1eac0 commit d18a6b6

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

src/StatisticsAnalysisTool/App.xaml.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using StatisticsAnalysisTool.ViewModels;
1515
using StatisticsAnalysisTool.Views;
1616
using System;
17+
using System.Diagnostics;
1718
using System.Reflection;
1819
using System.Runtime.InteropServices;
1920
using System.Threading.Tasks;
@@ -48,7 +49,6 @@ protected override async void OnStartup(StartupEventArgs e)
4849

4950
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
5051
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
51-
DispatcherUnhandledException += Application_DispatcherUnhandledException;
5252

5353
await SettingsController.LoadSettingsAsync();
5454

@@ -201,15 +201,16 @@ private void Application_DispatcherUnhandledException(object sender, DispatcherU
201201
{
202202
// Fixes a issue in the WPF clipboard handler.
203203
// It is necessary to handle the unhandled exception in the Application.DispatcherUnhandledException event.
204-
if (e.Exception is COMException { ErrorCode: -2147221040 })
204+
if (e.Exception is COMException comException
205+
&& comException.ErrorCode == -2147221040)
205206
{
206207
e.Handled = true;
207208
return;
208209
}
209210

210211
if (IsRecoverableLiveChartsTickerException(e.Exception))
211212
{
212-
Log.Warning(e.Exception, "Ignored a recoverable LiveCharts ticker disposal exception.");
213+
Log.Debug(e.Exception, "Ignored a recoverable LiveCharts ticker disposal exception.");
213214
e.Handled = true;
214215
return;
215216
}
@@ -232,18 +233,25 @@ private static bool IsRecoverableLiveChartsTickerException(Exception exception)
232233
return false;
233234
}
234235

235-
var stackTrace = exception.StackTrace;
236-
if (string.IsNullOrWhiteSpace(stackTrace))
236+
var stackTrace = new StackTrace(exception, false);
237+
return ContainsStackFrame(stackTrace, "LiveChartsCore.SkiaSharpView.WPF.Rendering.CompositionTargetTicker", "DisposeTicker")
238+
&& ContainsStackFrame(stackTrace, "LiveChartsCore.Motion.MotionCanvasComposer", "Dispose");
239+
}
240+
241+
private static bool ContainsStackFrame(StackTrace stackTrace, string typeName, string methodName)
242+
{
243+
foreach (var frame in stackTrace.GetFrames())
237244
{
238-
return false;
245+
var method = frame.GetMethod();
246+
if (method?.Name == methodName
247+
&& method != null
248+
&& method.DeclaringType?.FullName == typeName)
249+
{
250+
return true;
251+
}
239252
}
240253

241-
return stackTrace.Contains(
242-
"LiveChartsCore.SkiaSharpView.WPF.Rendering.CompositionTargetTicker.DisposeTicker",
243-
StringComparison.Ordinal)
244-
&& stackTrace.Contains(
245-
"LiveChartsCore.Motion.MotionCanvasComposer.Dispose",
246-
StringComparison.Ordinal);
254+
return false;
247255
}
248256

249257
protected override void OnExit(ExitEventArgs e)

0 commit comments

Comments
 (0)