Files
mirror-processhacker/1.x/trunk/ProcessHacker.Native/Threading/NativeThreadPool.cs
T
dmex 056f4c0914 PH1.x: Code Cleanup/Fixes
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4784 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2011-10-30 02:47:41 +00:00

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();
}
}
}