diff --git a/RetroBar/Utilities/ExplorerMonitor.cs b/RetroBar/Utilities/ExplorerMonitor.cs index bb9ed46c..2d916fd8 100644 --- a/RetroBar/Utilities/ExplorerMonitor.cs +++ b/RetroBar/Utilities/ExplorerMonitor.cs @@ -2,6 +2,7 @@ using ManagedShell.Interop; using System; using System.Windows.Forms; +using System.Windows.Threading; namespace RetroBar.Utilities { @@ -36,14 +37,16 @@ protected override void WndProc(ref Message m) { if (m.Msg == WM_TASKBARCREATEDMESSAGE) { - try - { - _windowManagerRef.ReopenTaskbars(); // Reopen taskbars if explorer.exe is restarted. - } - catch (Exception ex) - { - ShellLogger.Warning($"Error handling TaskbarCreated message on ExplorerMonitor: {ex.Message}"); - } + Dispatcher.CurrentDispatcher.BeginInvoke(() => { + try + { + _windowManagerRef.ReopenTaskbars(); // Reopen taskbars if explorer.exe is restarted. + } + catch (Exception ex) + { + ShellLogger.Warning($"Error handling TaskbarCreated message on ExplorerMonitor: {ex.Message}"); + } + }); } base.WndProc(ref m); // Call the base class to process other messages so we dont accidentally cause crashes or bugs. diff --git a/RetroBar/Utilities/WindowManager.cs b/RetroBar/Utilities/WindowManager.cs index 811001de..72b157ce 100644 --- a/RetroBar/Utilities/WindowManager.cs +++ b/RetroBar/Utilities/WindowManager.cs @@ -9,6 +9,8 @@ namespace RetroBar.Utilities { public class WindowManager : IDisposable { + private static object reopenLock = new object(); + private bool _isSettingDisplays; private int _pendingDisplayEvents; private List _screenState = new List(); @@ -55,8 +57,11 @@ private void Settings_PropertyChanged(object sender, System.ComponentModel.Prope public void ReopenTaskbars() { - closeTaskbars(); - openTaskbars(); + lock (reopenLock) + { + closeTaskbars(); + openTaskbars(); + } } public void NotifyDisplayChange(ScreenSetupReason reason)