public IAsyncResult BeginWait(TimeSpan timeout, bool throwTimeoutException, AsyncCallback callback, object state) { Exception exception = null; lock (this.thisLock) { if (!this.set) { WaitAsyncResult result = new WaitAsyncResult(timeout, throwTimeoutException, callback, state); this.Aborted += new WaitAsyncResult.AbortHandler(result.OnAborted); this.Faulted += new WaitAsyncResult.AbortHandler(result.OnFaulted); this.Signaled += new WaitAsyncResult.SignaledHandler(result.OnSignaled); result.Begin(); return(result); } if (this.communicationObject != null) { exception = this.GetException(); } } if (exception != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception); } return(new CompletedAsyncResult(callback, state)); }
public IAsyncResult BeginClose(TimeSpan timeout, AsyncCallback callback, object state) { bool flag = false; WaitAsyncResult result = null; lock (this.thisLock) { if (this.closed || (this.currentCount == 0)) { flag = true; } else { result = new WaitAsyncResult(timeout, true, callback, state); this.Signaled += new WaitAsyncResult.SignaledHandler(result.OnSignaled); } this.closed = true; } if (flag) { return(new CompletedAsyncResult(callback, state)); } result.Begin(); return(result); }
public bool EndTryWait(IAsyncResult result) { if (result is CompletedAsyncResult) { CompletedAsyncResult.End(result); return(true); } return(WaitAsyncResult.End(result)); }
public void EndClose(IAsyncResult result) { if (result is CompletedAsyncResult) { CompletedAsyncResult.End(result); } else { WaitAsyncResult.End(result); } }