protected void OnReceiveFirstTransfer(Transfer transfer) { Fx.Assert(transfer.DeliveryId.HasValue, "The first transfer must have a delivery id."); this.nextDeliveryId = transfer.DeliveryId.Value; }
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) { if (Fx.IsFatal(e)) { throw; } 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) { if (Fx.IsFatal(e)) { throw; } throw Fx.Exception.AsError(new CallbackException(CommonResources.AsyncCallbackThrewException, e)); } #pragma warning restore 1634 } return(true); }
public void DisposeDelivery(Delivery delivery, bool settled, DeliveryState state, bool noFlush) { if (delivery.Settled) { this.OnWindowMoved(1); return; } bool scheduleTimer = false; Delivery toDispose = null; lock (this.syncRoot) { delivery.StateChanged = true; delivery.Settled = settled; delivery.State = state; if (!delivery.Batchable) { delivery.StateChanged = false; toDispose = delivery; if (delivery.Settled) { Delivery.Remove(ref this.firstUnsettled, ref this.lastUnsettled, delivery); } } else if (this.sendingDisposition || noFlush) { return; } else if (this.session.settings.DispositionInterval == TimeSpan.Zero || ++this.needDispositionCount >= this.session.settings.DispositionThreshold) { this.sendingDisposition = true; this.needDispositionCount = 0; } else if (!this.timerScheduled) { this.timerScheduled = true; scheduleTimer = true; } } if (toDispose != null) { this.SendDisposition(new DispositionInfo() { First = toDispose }); if (delivery.Settled) { this.OnWindowMoved(1); } } else if (scheduleTimer) { Fx.Assert(this.dispositionTimer != null, "Disposition timer cannot be null"); this.dispositionTimer.Change(this.session.settings.DispositionInterval, Timeout.InfiniteTimeSpan); } else { this.SendDisposition(); } }
public DefaultActionItem(WaitCallback callback, object state) { Fx.Assert(callback != null, "Shouldn't instantiate an object to wrap a null callback"); this.callback = callback; this.state = state; }
public static void End(IAsyncResult result) { Fx.AssertAndThrowFatal(result.IsCompleted, "CompletedAsyncResult was not completed!"); AsyncResult.End <CompletedAsyncResult>(result); }
public static void Schedule(WaitCallback callback, object state) { Fx.Assert(callback != null, "A null callback was passed for Schedule!"); ThreadPool.QueueUserWorkItem(callback, state); }
bool CompleteInternal(bool syncComplete, Exception exception) { Fx.Assert(exception != null || this.setTimerCalled, "Must call SetTimer."); return(this.TryComplete(syncComplete, exception)); }