PowerToys/src/modules/launcher/PowerLauncher/Helper/NativeEventWaiter.cs

32 lines
1015 B
C#
Raw Normal View History

// 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;
using System.Threading;
using System.Windows;
2020-12-10 20:56:16 +08:00
using Wox.Plugin.Logger;
namespace PowerLauncher.Helper
{
public static class NativeEventWaiter
{
public static void WaitForEventLoop(string eventName, Action callback)
{
new Thread(() =>
{
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
while (true)
{
if (eventHandle.WaitOne())
{
2020-12-10 20:56:16 +08:00
Log.Info("Successfully waited for POWER_LAUNCHER_SHARED_EVENT", MethodBase.GetCurrentMethod().DeclaringType);
Application.Current.Dispatcher.Invoke(callback);
}
}
}).Start();
}
}
}