fix exception caused by data race

This commit is contained in:
Kang Yu 2024-08-11 16:32:22 -07:00
parent bed63a11f4
commit 2d14ef2cb9

View file

@ -89,6 +89,7 @@ namespace PersistentWindows.Common
private IntPtr realForeGroundWindow = IntPtr.Zero; private IntPtr realForeGroundWindow = IntPtr.Zero;
public Dictionary<uint, string> processCmd = new Dictionary<uint, string>(); public Dictionary<uint, string> processCmd = new Dictionary<uint, string>();
private HashSet<IntPtr> fullScreenGamingWindows = new HashSet<IntPtr>(); private HashSet<IntPtr> fullScreenGamingWindows = new HashSet<IntPtr>();
private IntPtr fullScreenGamingWindow = IntPtr.Zero;
private bool exitFullScreenGaming = false; private bool exitFullScreenGaming = false;
private POINT initCursorPos; private POINT initCursorPos;
private bool freezeCapture = false; private bool freezeCapture = false;
@ -528,6 +529,13 @@ namespace PersistentWindows.Common
if (restoringFromMem) if (restoringFromMem)
return; return;
if (fullScreenGamingWindow == foreGroundWindow)
{
fullScreenGamingWindows.Add(fullScreenGamingWindow);
fullScreenGamingWindow = IntPtr.Zero;
return;
}
if (fullScreenGamingWindows.Contains(foreGroundWindow)) if (fullScreenGamingWindows.Contains(foreGroundWindow))
return; return;
@ -778,7 +786,7 @@ namespace PersistentWindows.Common
{ {
if (IsNewWindow(foreGroundWindow)) if (IsNewWindow(foreGroundWindow))
{ {
fullScreenGamingWindows.Add(foreGroundWindow); fullScreenGamingWindow = foreGroundWindow;
Log.Event($"enter full-screen gaming mode {displayKey} {GetWindowTitle(foreGroundWindow)}"); Log.Event($"enter full-screen gaming mode {displayKey} {GetWindowTitle(foreGroundWindow)}");
} }
else else
@ -1573,6 +1581,7 @@ namespace PersistentWindows.Common
if (fullScreenGamingWindows.Contains(hwnd)) if (fullScreenGamingWindows.Contains(hwnd))
{ {
fullScreenGamingWindows.Remove(hwnd); fullScreenGamingWindows.Remove(hwnd);
fullScreenGamingWindow = IntPtr.Zero;
exitFullScreenGaming = true; exitFullScreenGaming = true;
} }
dualPosSwitchWindows.Remove(hwnd); dualPosSwitchWindows.Remove(hwnd);