From 83d3c85f3e0d22be7d88a373618ce1d22d050794 Mon Sep 17 00:00:00 2001 From: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:51:11 +0100 Subject: [PATCH] [Settings]Fix crash caused by dangling thread (#35603) * Fix crash caused by dangling thread * Fix process access to be able to WaitForSingleObject it --- src/runner/settings_window.cpp | 2 +- src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp index 7e56622443..6127eb2c60 100644 --- a/src/runner/settings_window.cpp +++ b/src/runner/settings_window.cpp @@ -625,7 +625,7 @@ void close_settings_window() if (g_settings_process_id != 0) { SetEvent(g_terminateSettingsEvent); - wil::unique_handle proc{ OpenProcess(PROCESS_TERMINATE, false, g_settings_process_id) }; + wil::unique_handle proc{ OpenProcess(PROCESS_ALL_ACCESS, false, g_settings_process_id) }; if (proc) { WaitForSingleObject(proc.get(), 1500); diff --git a/src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs b/src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs index 0aee5d3fd6..b8094cd57f 100644 --- a/src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs +++ b/src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs @@ -4,7 +4,7 @@ using System; using System.Threading; - +using System.Threading.Tasks; using Microsoft.UI.Dispatching; namespace Microsoft.PowerToys.Settings.UI.Helpers @@ -14,7 +14,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers public static void WaitForEventLoop(string eventName, Action callback) { var dispatcherQueue = DispatcherQueue.GetForCurrentThread(); - new Thread(() => + new Task(() => { var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName); while (true)