From 0349383d082e604a6111e79f1253645ae7bb0473 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind <32061677+arjunbalgovind@users.noreply.github.com> Date: Mon, 31 Aug 2020 10:22:00 -0700 Subject: [PATCH] [PowerToys Run] Fix error reporting window for exceptions that are not on the dispatcher thread (#6221) * Possible fix for dispatcher error * Revert changes on other files --- .../PowerLauncher/Helper/ErrorReporting.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/Helper/ErrorReporting.cs b/src/modules/launcher/PowerLauncher/Helper/ErrorReporting.cs index b1b32f411c..2cc5d7be60 100644 --- a/src/modules/launcher/PowerLauncher/Helper/ErrorReporting.cs +++ b/src/modules/launcher/PowerLauncher/Helper/ErrorReporting.cs @@ -12,7 +12,7 @@ namespace PowerLauncher.Helper { public static class ErrorReporting { - private static void Report(Exception e) + private static void Report(Exception e, bool waitForClose) { if (e != null) { @@ -20,20 +20,31 @@ namespace PowerLauncher.Helper logger.Fatal(ExceptionFormatter.FormatException(e)); var reportWindow = new ReportWindow(e); - reportWindow.Show(); + + if (waitForClose) + { + reportWindow.ShowDialog(); + } + else + { + reportWindow.Show(); + } } } public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e) { // handle non-ui thread exceptions - Report((Exception)e?.ExceptionObject); + System.Windows.Application.Current.Dispatcher.Invoke(() => + { + Report((Exception)e?.ExceptionObject, true); + }); } public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { // handle ui thread exceptions - Report(e?.Exception); + Report(e?.Exception, false); // prevent application exist, so the user can copy prompted error info e.Handled = true;