From 57e60287ff484abd6a127d85d1a73b6a0f60a468 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Thu, 26 Aug 2021 12:51:20 +0200 Subject: [PATCH] msgbox fix --- src/Misc/Msg.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Misc/Msg.cs b/src/Misc/Msg.cs index 0a489c5..e08e168 100644 --- a/src/Misc/Msg.cs +++ b/src/Misc/Msg.cs @@ -1,17 +1,12 @@  using System; +using System.Threading; using System.Windows; -using WinForms = System.Windows.Forms; - -using static mpvnet.Global; - using MsgBoxEx; public class Msg { - private static readonly string WindowTitle = WinForms.Application.ProductName; - public static void ShowInfo(object title) { Show(title, MessageBoxImage.Information); @@ -44,8 +39,19 @@ public class Msg MessageBoxButton buttons = MessageBoxButton.OK, string details = null) { - string msg = title?.ToString().TrimEx(); - MessageBoxEx.DetailsText = details; - return MessageBoxEx.OpenMessageBox(null, msg, WindowTitle, buttons, img); + MessageBoxResult fn() + { + string msg = title?.ToString().TrimEx(); + MessageBoxEx.DetailsText = details; + string windowTitle = System.Windows.Forms.Application.ProductName; + return MessageBoxEx.OpenMessageBox(null, msg, windowTitle, buttons, img); + } + + ApartmentState state = Thread.CurrentThread.GetApartmentState(); + + if (state == ApartmentState.STA) + return fn(); + else + return Application.Current.Dispatcher.Invoke(fn); } }