diff --git a/src/modules/Hosts/Hosts/Helpers/NativeEventWaiter.cs b/src/modules/Hosts/Hosts/Helpers/NativeEventWaiter.cs index b63468d553..9737cdae04 100644 --- a/src/modules/Hosts/Hosts/Helpers/NativeEventWaiter.cs +++ b/src/modules/Hosts/Hosts/Helpers/NativeEventWaiter.cs @@ -14,7 +14,7 @@ namespace Hosts.Helpers public static void WaitForEventLoop(string eventName, Action callback) { var dispatcherQueue = DispatcherQueue.GetForCurrentThread(); - new Thread(() => + var t = new Thread(() => { var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName); while (true) @@ -24,7 +24,10 @@ namespace Hosts.Helpers dispatcherQueue.TryEnqueue(() => callback()); } } - }).Start(); + }); + + t.IsBackground = true; + t.Start(); } } } diff --git a/src/modules/peek/Peek.UI/NativeEventWaiter.cs b/src/modules/peek/Peek.UI/NativeEventWaiter.cs index e35ad98cbb..c49d8b0800 100644 --- a/src/modules/peek/Peek.UI/NativeEventWaiter.cs +++ b/src/modules/peek/Peek.UI/NativeEventWaiter.cs @@ -14,7 +14,7 @@ namespace Peek.UI.Native public static void WaitForEventLoop(string eventName, Action callback) { var dispatcherQueue = DispatcherQueue.GetForCurrentThread(); - new Thread(() => + var t = new Thread(() => { var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName); while (true) @@ -24,7 +24,10 @@ namespace Peek.UI.Native dispatcherQueue.TryEnqueue(() => callback()); } } - }).Start(); + }); + + t.IsBackground = true; + t.Start(); } } } diff --git a/src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs b/src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs index b8094cd57f..de6707dd38 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 Task(() => + var t = new Thread(() => { var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName); while (true) @@ -24,7 +24,10 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers dispatcherQueue.TryEnqueue(() => callback()); } } - }).Start(); + }); + + t.IsBackground = true; + t.Start(); } } }