Skip to content

Commit

Permalink
Merge pull request #960 from dremin/fix-reopen-race
Browse files Browse the repository at this point in the history
Fix reopen race
  • Loading branch information
dremin authored Nov 21, 2024
2 parents 97392db + 224791f commit 09e5f27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
19 changes: 11 additions & 8 deletions RetroBar/Utilities/ExplorerMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ManagedShell.Interop;
using System;
using System.Windows.Forms;
using System.Windows.Threading;

namespace RetroBar.Utilities
{
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions RetroBar/Utilities/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppBarScreen> _screenState = new List<AppBarScreen>();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 09e5f27

Please sign in to comment.