From 5e145ae2be76e5e9cd2d901651f0741f64b8b677 Mon Sep 17 00:00:00 2001 From: Quajak Date: Fri, 29 May 2020 09:35:53 +0200 Subject: [PATCH] Made MessageBox always use UI thread --- source/Cosmos.VS.DebugEngine/AD7Util.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/Cosmos.VS.DebugEngine/AD7Util.cs b/source/Cosmos.VS.DebugEngine/AD7Util.cs index 979ae49cd..18296acc5 100644 --- a/source/Cosmos.VS.DebugEngine/AD7Util.cs +++ b/source/Cosmos.VS.DebugEngine/AD7Util.cs @@ -14,10 +14,23 @@ namespace Cosmos.VS.DebugEngine public static void MessageBox(string message, string title = "Cosmos Debug Engine") { - ThreadHelper.ThrowIfNotOnUIThread(); + if (!ThreadHelper.CheckAccess()) + { + ThreadHelper.JoinableTaskFactory.Run(async delegate { + // Switch to main thread + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, message, title, - OLEMSGICON.OLEMSGICON_NOICON, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + + VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, message, title, + OLEMSGICON.OLEMSGICON_NOICON, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + }); + + } + else + { + VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, message, title, + OLEMSGICON.OLEMSGICON_NOICON, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + } } } }