public IAsyncResult BeginInvoke(AsyncCallback callback, object state) { AsyncCallback wrappedCallback = (callback != null) ? ar => _syncContext.Sync(() => callback(ar)) : (AsyncCallback)null; return(_itemThunk.BeginInvoke(wrappedCallback, state)); }
public static void Sync(this SynchronizationContext syncContext, Action action) { syncContext.Sync(delegate { action(); return(default(AsyncVoid)); }); }
public TResult ExecuteEndDelegateOnce() { if (!_executeEndDelegateOnceEvent.Signal()) { throw new ArgumentException(MvcResources.AsyncCommon_ResultAlreadyExecuted, "asyncResult"); } Timer timer = _timer; if (timer != null) { lock (_timerLockObj) { _timerDisposed = true; timer.Dispose(); } } if (_timedOut) { throw new TimeoutException(); } return(_syncContext.Sync(() => EndCallback(_innerAsyncResult))); }
public static AsyncCallback WrapCallbackForSynchronizedExecution( AsyncCallback callback, SynchronizationContext context) { if (callback == null || context == null) { return(callback); } return(delegate(IAsyncResult result) { if (result.CompletedSynchronously) { callback(result); } else { context.Sync(() => callback(result)); } }); }
public static AsyncCallback WrapCallbackForSynchronizedExecution(AsyncCallback callback, SynchronizationContext syncContext) { if (callback == null || syncContext == null) { return(callback); } AsyncCallback newCallback = delegate(IAsyncResult asyncResult) { if (asyncResult.CompletedSynchronously) { callback(asyncResult); } else { // Only take the application lock if this request completed asynchronously, // else we might end up in a deadlock situation. syncContext.Sync(() => callback(asyncResult)); } }; return(newCallback); }
/// <summary> /// Executes a callback in the current synchronization context, /// which gives access to HttpContext and related items. /// </summary> /// <param name="action">The callback action.</param> public virtual void Sync(Action action) { _context.Sync(action); }
public void Post(Action d) { SynchronizationContext.Sync(d); }
private void CallbackUsingSyncContext() { _callbackSyncContext.Sync(() => _originalCallback(this)); }