Made MessageBox always use UI thread

This commit is contained in:
Quajak 2020-05-29 09:35:53 +02:00 committed by GitHub
parent 9f300f940e
commit 5e145ae2be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}
}
}
}