Skip to content

Commit c61ace3

Browse files
committed
Fix: Fixed an issue when multiple threads handle CanWindowToFront flag
1 parent 24750cf commit c61ace3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Files.App/MainWindow.xaml.cs

+13-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public sealed partial class MainWindow : WinUIEx.WindowEx
2020

2121
public nint WindowHandle { get; }
2222
private bool CanWindowToFront { get; set; } = true;
23+
private readonly object _canWindowToFrontLock = new();
2324

2425
public MainWindow()
2526
{
@@ -343,15 +344,18 @@ x.tabItem.NavigationParameter.NavigationParameter is PaneNavigationArguments pan
343344
}
344345
}
345346

346-
public bool SetCanWindowToFront(bool canWindowToFront)
347-
{
348-
if (CanWindowToFront != canWindowToFront)
349-
{
350-
CanWindowToFront = canWindowToFront;
351-
return true;
352-
}
353-
return false;
354-
}
347+
public bool SetCanWindowToFront(bool canWindowToFront)
348+
{
349+
lock (_canWindowToFrontLock)
350+
{
351+
if (CanWindowToFront != canWindowToFront)
352+
{
353+
CanWindowToFront = canWindowToFront;
354+
return true;
355+
}
356+
return false;
357+
}
358+
}
355359

356360
private const int WM_WINDOWPOSCHANGING = 0x0046;
357361
private void WindowManager_WindowMessageReceived(object? sender, WinUIEx.Messaging.WindowMessageEventArgs e)

0 commit comments

Comments
 (0)