mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
056f4c0914
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4784 21ef857c-d57f-4fe0-8362-d861dc6d29cd
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using ProcessHacker.Native.Api;
|
|
|
|
namespace ProcessHacker.Native.Threading
|
|
{
|
|
public delegate void RegisterWaitCallback(object argument, bool timeout);
|
|
|
|
public static class NativeThreadPool
|
|
{
|
|
public static void QueueWorkItem(Action<object> work, object argument)
|
|
{
|
|
Win32.RtlQueueWorkItem(context => work(argument), IntPtr.Zero, WtFlags.ExecuteDefault).ThrowIf();
|
|
}
|
|
|
|
public static IntPtr RegisterWait(IntPtr handle, RegisterWaitCallback callback, object argument, int timeoutMilliseconds)
|
|
{
|
|
IntPtr waitHandle;
|
|
|
|
Win32.RtlRegisterWait(
|
|
out waitHandle,
|
|
handle,
|
|
(context, timeout) => callback(argument, timeout),
|
|
IntPtr.Zero,
|
|
timeoutMilliseconds,
|
|
WtFlags.ExecuteDefault
|
|
).ThrowIf();
|
|
|
|
return waitHandle;
|
|
}
|
|
|
|
public static void UnregisterWait(IntPtr waitHandle)
|
|
{
|
|
Win32.RtlDeregisterWait(waitHandle).ThrowIf();
|
|
}
|
|
}
|
|
}
|