mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
b02427417c
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@5614 21ef857c-d57f-4fe0-8362-d861dc6d29cd
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using ProcessHacker.Native.Api;
|
|
using ProcessHacker.Native.Objects;
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|