public static RegisterWaitForSingleObject ( System waitObject, System callBack, object state, System timeout, bool executeOnlyOnce ) : System.Threading.RegisteredWaitHandle | ||
waitObject | System | |
callBack | System | |
state | object | |
timeout | System | |
executeOnlyOnce | bool | |
return | System.Threading.RegisteredWaitHandle |
public static Task WaitAsync(this SemaphoreSlim semaphore) { if (semaphore.Wait(0)) { return(TaskEx.TaskCompleted); } var tcs = new TaskCompletionSource <bool>(); WaitOrTimerCallback waitOrTimerCallback = null; waitOrTimerCallback = (state, timedOut) => { if (semaphore.Wait(0)) { tcs.TrySetResult(true); return; } ThreadPool.RegisterWaitForSingleObject(semaphore.AvailableWaitHandle, waitOrTimerCallback, null, Timeout.Infinite, true); }; waitOrTimerCallback(null, false); return(tcs.Task); }
public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(ThreadPool.RegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce, ref stackMark, true)); }
public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) { return(ThreadPool.RegisterWaitForSingleObject(waitObject, callBack, state, (long)((ulong)millisecondsTimeOutInterval), executeOnlyOnce)); }
/// <summary>Registers a delegate to wait for a <see cref="T:System.Threading.WaitHandle" />, specifying a <see cref="T:System.TimeSpan" /> value for the time-out.</summary> /// <returns>The <see cref="T:System.Threading.RegisteredWaitHandle" /> that encapsulates the native handle.</returns> /// <param name="waitObject">The <see cref="T:System.Threading.WaitHandle" /> to register. Use a <see cref="T:System.Threading.WaitHandle" /> other than <see cref="T:System.Threading.Mutex" />.</param> /// <param name="callBack">The <see cref="T:System.Threading.WaitOrTimerCallback" /> delegate to call when the <paramref name="waitObject" /> parameter is signaled. </param> /// <param name="state">The object passed to the delegate. </param> /// <param name="timeout">The time-out represented by a <see cref="T:System.TimeSpan" />. If <paramref name="timeout" /> is 0 (zero), the function tests the object's state and returns immediately. If <paramref name="timeout" /> is -1, the function's time-out interval never elapses. </param> /// <param name="executeOnlyOnce">true to indicate that the thread will no longer wait on the <paramref name="waitObject" /> parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered. </param> /// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="timeout" /> parameter is less than -1. </exception> /// <exception cref="T:System.NotSupportedException">The <paramref name="timeout" /> parameter is greater than <see cref="F:System.Int32.MaxValue" />. </exception> /// <filterpriority>1</filterpriority> public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, TimeSpan timeout, bool executeOnlyOnce) { return(ThreadPool.RegisterWaitForSingleObject(waitObject, callBack, state, (long)timeout.TotalMilliseconds, executeOnlyOnce)); }