mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
Don't use Environment.Exit (#20532)
* [Awake] Don't use Process.Exit and move to CsWin32 * [PowerLauncher] Remove unused API * [ColorPicker] Use cancellable NativeEventWaiter + cleanup using * [TextExtractor] Don't use Environment.Exit * [MeasureTool] Don't use Environment.Exit(0); * [FZE] don't use Environment.Exit and fix WaitForPowerToysRunner
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ControlzEx.Theming;
|
||||
|
||||
namespace Common.UI
|
||||
|
||||
33
src/common/Common.UI/NativeEventWaiter.cs
Normal file
33
src/common/Common.UI/NativeEventWaiter.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using Dispatcher = System.Windows.Threading.Dispatcher;
|
||||
|
||||
namespace Common.UI
|
||||
{
|
||||
public static class NativeEventWaiter
|
||||
{
|
||||
public static void WaitForEventLoop(string eventName, Action callback, Dispatcher dispatcher, CancellationToken cancel)
|
||||
{
|
||||
new Thread(() =>
|
||||
{
|
||||
var eventHandle = new EventWaitHandle(false, EventResetMode.ManualReset, eventName);
|
||||
while (true)
|
||||
{
|
||||
if (WaitHandle.WaitAny(new WaitHandle[] { cancel.WaitHandle, eventHandle }) == 1)
|
||||
{
|
||||
dispatcher.BeginInvoke(callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user