2020-09-21 18:44:16 +08:00
|
|
|
|
// 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;
|
2020-12-10 20:56:16 +08:00
|
|
|
|
using System.Reflection;
|
2020-09-21 18:44:16 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
2020-12-10 20:56:16 +08:00
|
|
|
|
using Wox.Plugin.Logger;
|
2020-09-21 18:44:16 +08:00
|
|
|
|
|
|
|
|
|
namespace PowerLauncher.Helper
|
|
|
|
|
{
|
|
|
|
|
public static class NativeEventWaiter
|
|
|
|
|
{
|
2022-09-12 18:20:24 +08:00
|
|
|
|
public static void WaitForEventLoop(string eventName, Action callback, CancellationToken cancel)
|
2020-09-21 18:44:16 +08:00
|
|
|
|
{
|
|
|
|
|
new Thread(() =>
|
|
|
|
|
{
|
|
|
|
|
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2022-09-12 18:20:24 +08:00
|
|
|
|
if (WaitHandle.WaitAny(new WaitHandle[] { cancel.WaitHandle, eventHandle }) == 1)
|
2020-09-21 18:44:16 +08:00
|
|
|
|
{
|
2021-03-20 01:03:12 +08:00
|
|
|
|
Log.Info($"Successfully waited for {eventName}", MethodBase.GetCurrentMethod().DeclaringType);
|
2020-09-21 18:44:16 +08:00
|
|
|
|
Application.Current.Dispatcher.Invoke(callback);
|
|
|
|
|
}
|
2022-09-12 18:20:24 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-21 18:44:16 +08:00
|
|
|
|
}
|
|
|
|
|
}).Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|