public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
long millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
if (millisecondsTimeOutInterval < -1)
throw new ArgumentOutOfRangeException ("timeout", "timeout < -1");
if (millisecondsTimeOutInterval > Int32.MaxValue)
throw new NotSupportedException ("Timeout is too big. Maximum is Int32.MaxValue");
TimeSpan timeout = new TimeSpan (0, 0, 0, 0, (int) millisecondsTimeOutInterval);
RegisteredWaitHandle waiter = new RegisteredWaitHandle (waitObject, callBack, state,
timeout, executeOnlyOnce);
QueueUserWorkItem (new WaitCallback (waiter.Wait), null);
return waiter;
}