mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 14:59:16 +08:00
[General]Use background threads in NativeEventWaiters to prevent dangling threads (#35637)
* Use Tasks in NativeEventWaiters to prevent dangling threads * Use background threads instead
This commit is contained in:
parent
b204353308
commit
72a481b17c
@ -14,7 +14,7 @@ namespace Hosts.Helpers
|
|||||||
public static void WaitForEventLoop(string eventName, Action callback)
|
public static void WaitForEventLoop(string eventName, Action callback)
|
||||||
{
|
{
|
||||||
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||||
new Thread(() =>
|
var t = new Thread(() =>
|
||||||
{
|
{
|
||||||
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
||||||
while (true)
|
while (true)
|
||||||
@ -24,7 +24,10 @@ namespace Hosts.Helpers
|
|||||||
dispatcherQueue.TryEnqueue(() => callback());
|
dispatcherQueue.TryEnqueue(() => callback());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).Start();
|
});
|
||||||
|
|
||||||
|
t.IsBackground = true;
|
||||||
|
t.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ namespace Peek.UI.Native
|
|||||||
public static void WaitForEventLoop(string eventName, Action callback)
|
public static void WaitForEventLoop(string eventName, Action callback)
|
||||||
{
|
{
|
||||||
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||||
new Thread(() =>
|
var t = new Thread(() =>
|
||||||
{
|
{
|
||||||
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
||||||
while (true)
|
while (true)
|
||||||
@ -24,7 +24,10 @@ namespace Peek.UI.Native
|
|||||||
dispatcherQueue.TryEnqueue(() => callback());
|
dispatcherQueue.TryEnqueue(() => callback());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).Start();
|
});
|
||||||
|
|
||||||
|
t.IsBackground = true;
|
||||||
|
t.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.UI.Dispatching;
|
using Microsoft.UI.Dispatching;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||||
@ -14,7 +14,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
public static void WaitForEventLoop(string eventName, Action callback)
|
public static void WaitForEventLoop(string eventName, Action callback)
|
||||||
{
|
{
|
||||||
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||||
new Task(() =>
|
var t = new Thread(() =>
|
||||||
{
|
{
|
||||||
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
||||||
while (true)
|
while (true)
|
||||||
@ -24,7 +24,10 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
dispatcherQueue.TryEnqueue(() => callback());
|
dispatcherQueue.TryEnqueue(() => callback());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).Start();
|
});
|
||||||
|
|
||||||
|
t.IsBackground = true;
|
||||||
|
t.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user