protected AsyncResult(AsyncCallback callback, object state) { _callback = callback; AsyncState = state; #if DEBUG _marker = new UncompletedAsyncResultMarker(this); #endif }
protected AsyncResult(AsyncCallback callback, object state) { this.callback = callback; this.state = state; this.thisLock = new object(); #if DEBUG this.marker = new UncompletedAsyncResultMarker(this); #endif }
protected bool TryComplete(bool didCompleteSynchronously, Exception exception) { lock (this.ThisLock) { if (this.isCompleted) { return(false); } this.exception = exception; this.isCompleted = true; } #if DEBUG this.marker.AsyncResult = null; this.marker = null; #endif this.completedSynchronously = didCompleteSynchronously; if (this.OnCompleting != null) { // Allow exception replacement, like a catch/throw pattern. try { this.OnCompleting(this, this.exception); } catch (Exception e) when(!Fx.IsFatal(e)) { this.exception = e; } } if (didCompleteSynchronously) { // If we completedSynchronously, then there's no chance that the manualResetEvent was created so // we don't need to worry about a race Fx.Assert(this.manualResetEvent == null, "No ManualResetEvent should be created for a synchronous AsyncResult."); } else { lock (this.ThisLock) { if (this.manualResetEvent != null) { this.manualResetEvent.Set(); } } } if (this.callback != null) { try { if (this.VirtualCallback != null) { this.VirtualCallback(this.callback, this); } else { this.callback(this); } } #pragma warning disable 1634 #pragma warning suppress 56500 // transferring exception to another thread catch (Exception e) when(!Fx.IsFatal(e)) { throw new CallbackException(CommonResources.AsyncCallbackThrewException, e); } #pragma warning restore 1634 } return(true); }
protected void Complete(bool completedSynchronously) { if (this.isCompleted) { throw new InvalidOperationException(string.Format(SR.AsyncResultCompletedTwice, GetType())); } #if DEBUG this.marker.AsyncResult = null; this.marker = null; if (this.completeStack == null) { this.completeStack = new StackTrace(); } #endif this.completedSynchronously = completedSynchronously; if (this.OnCompleting != null) { // Allow exception replacement, like a catch/throw pattern. try { this.OnCompleting(this, this.exception); } catch (Exception exception) { if (Utility.IsFatal(exception)) { throw; } this.exception = exception; } } if (completedSynchronously) { // If we completedSynchronously, then there's no chance that the manualResetEvent was created so // we don't need to worry about a threading issue this.isCompleted = true; } else { lock (this.ThisLock) { this.isCompleted = true; if (this.manualResetEvent != null) { this.manualResetEvent.Set(); } } } if (this.callback != null) { try { if (this.VirtualCallback != null) { this.VirtualCallback(this.callback, this); } else { this.callback(this); } } #pragma warning disable 1634 #pragma warning suppress 56500 // transferring exception to another thread catch (Exception e) { if (Utility.IsFatal(e)) { throw; } throw new InvalidOperationException(); // CallbackException(InternalSR.AsyncCallbackThrewException, e)); } #pragma warning restore 1634 } }
protected void Complete(bool completedSynchronously) { if (this.isCompleted) { throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.AsyncResultCompletedTwice(GetType()))); } #if DEBUG this.marker.AsyncResult = null; this.marker = null; if (!Fx.FastDebug && completeStack == null) { completeStack = new StackTrace(); } #endif this.completedSynchronously = completedSynchronously; if (OnCompleting != null) { // Allow exception replacement, like a catch/throw pattern. try { OnCompleting(this, this.exception); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.exception = exception; } } if (completedSynchronously) { // If we completedSynchronously, then there's no chance that the manualResetEvent was created so // we don't need to worry about a ---- Fx.Assert(this.manualResetEvent == null, "No ManualResetEvent should be created for a synchronous AsyncResult."); this.isCompleted = true; } else { lock (ThisLock) { this.isCompleted = true; if (this.manualResetEvent != null) { this.manualResetEvent.Set(); } } } if (this.callback != null) { try { if (VirtualCallback != null) { VirtualCallback(this.callback, this); } else { this.callback(this); } } #pragma warning disable 1634 #pragma warning suppress 56500 // transferring exception to another thread catch (Exception e) { if (Fx.IsFatal(e)) { throw; } throw Fx.Exception.AsError(new CallbackException(InternalSR.AsyncCallbackThrewException, e)); } #pragma warning restore 1634 } }