internal bool FinishPostingAsyncOp(ref CallbackClosure closure) { ExecutionContext context; if ((this._Flags & (StateFlags.PostBlockFinished | StateFlags.PostBlockStarted)) != StateFlags.PostBlockStarted) { return(false); } this._Flags |= StateFlags.PostBlockFinished; CallbackClosure closure2 = closure; if (closure2 == null) { context = null; } else if (!closure2.IsCompatible(base.AsyncCallback)) { closure = null; context = null; } else { base.AsyncCallback = closure2.AsyncCallback; context = closure2.Context; } bool flag = this.CaptureOrComplete(ref context, true); if (((closure == null) && (base.AsyncCallback != null)) && (context != null)) { closure = new CallbackClosure(context, base.AsyncCallback); } return(flag); }
// Call this when returning control to the user. Allows a cached Callback Closure to be supplied and used // as appropriate, and replaced with a new one. internal bool FinishPostingAsyncOp(ref CallbackClosure?closure) { // Ignore this call if StartPostingAsyncOp() failed or wasn't called, or this has already been called. if ((_flags & (StateFlags.PostBlockStarted | StateFlags.PostBlockFinished)) != StateFlags.PostBlockStarted) { return(false); } _flags |= StateFlags.PostBlockFinished; // Need a copy of this ref argument since it can be used in many of these calls simultaneously. CallbackClosure? closureCopy = closure; ExecutionContext?cachedContext; if (closureCopy == null) { cachedContext = null; } else { if (!closureCopy.IsCompatible(AsyncCallback)) { // Clear the cache as soon as a method is called with incompatible parameters. closure = null; cachedContext = null; } else { // If it succeeded, we want to replace our context/callback with the one from the closure. // Using the closure's instance of the callback is probably overkill, but safer. AsyncCallback = closureCopy.AsyncCallback; cachedContext = closureCopy.Context; } } bool calledCallback = CaptureOrComplete(ref cachedContext, true); // Set up new cached context if we didn't use the previous one. if (closure == null && AsyncCallback != null && cachedContext != null) { closure = new CallbackClosure(cachedContext, AsyncCallback); } return(calledCallback); }
internal bool FinishPostingAsyncOp(ref CallbackClosure closure) { ExecutionContext context; if ((this._Flags & (StateFlags.PostBlockFinished | StateFlags.PostBlockStarted)) != StateFlags.PostBlockStarted) { return false; } this._Flags |= StateFlags.PostBlockFinished; CallbackClosure closure2 = closure; if (closure2 == null) { context = null; } else if (!closure2.IsCompatible(base.AsyncCallback)) { closure = null; context = null; } else { base.AsyncCallback = closure2.AsyncCallback; context = closure2.Context; } bool flag = this.CaptureOrComplete(ref context, true); if (((closure == null) && (base.AsyncCallback != null)) && (context != null)) { closure = new CallbackClosure(context, base.AsyncCallback); } return flag; }
// Call this when returning control to the user. Allows a cached Callback Closure to be supplied and used // as appropriate, and replaced with a new one. internal bool FinishPostingAsyncOp(ref CallbackClosure closure) { // Ignore this call if StartPostingAsyncOp() failed or wasn't called, or this has already been called. if ((_flags & (StateFlags.PostBlockStarted | StateFlags.PostBlockFinished)) != StateFlags.PostBlockStarted) { return false; } _flags |= StateFlags.PostBlockFinished; // Need a copy of this ref argument since it can be used in many of these calls simultaneously. CallbackClosure closureCopy = closure; ExecutionContext cachedContext; if (closureCopy == null) { cachedContext = null; } else { if (!closureCopy.IsCompatible(AsyncCallback)) { // Clear the cache as soon as a method is called with incompatible parameters. closure = null; cachedContext = null; } else { // If it succeeded, we want to replace our context/callback with the one from the closure. // Using the closure's instance of the callback is probably overkill, but safer. AsyncCallback = closureCopy.AsyncCallback; cachedContext = closureCopy.Context; } } bool calledCallback = CaptureOrComplete(ref cachedContext, true); // Set up new cached context if we didn't use the previous one. if (closure == null && AsyncCallback != null && cachedContext != null) { closure = new CallbackClosure(cachedContext, AsyncCallback); } return calledCallback; }