/// <summary> /// Creates an async-compatible manual-reset event. /// </summary> /// <param name="set">Whether the manual-reset event is initially set or unset.</param> public AsyncManualResetEvent(bool set) { _mutex = new object(); _tcs = TaskCompletionSourceExtensions.CreateAsyncTaskSource <object>(); if (set) { _tcs.TrySetResult(null); } }
/// <summary> /// Resets the event. If the event is already reset, this method does nothing. /// </summary> public void Reset() { lock (_mutex) { if (_tcs.Task.IsCompleted) { _tcs = TaskCompletionSourceExtensions.CreateAsyncTaskSource <object>(); } } }