Use background threads instead

This commit is contained in:
Stefan Markovic 2024-10-29 10:21:24 +01:00
parent 6f7dc4f77f
commit 0200a76de7
3 changed files with 16 additions and 9 deletions

View File

@ -4,7 +4,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.UI.Dispatching;
@ -15,7 +14,7 @@ namespace Hosts.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)
@ -25,7 +24,10 @@ namespace Hosts.Helpers
dispatcherQueue.TryEnqueue(() => callback());
}
}
}).Start();
});
t.IsBackground = true;
t.Start();
}
}
}

View File

@ -4,7 +4,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.UI.Dispatching;
@ -15,7 +14,7 @@ namespace Peek.UI.Native
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)
@ -25,7 +24,10 @@ namespace Peek.UI.Native
dispatcherQueue.TryEnqueue(() => callback());
}
}
}).Start();
});
t.IsBackground = true;
t.Start();
}
}
}

View File

@ -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();
}
}
}