private void CompleteSingleOperation(BatchManager <TItem> .BatchedObjectsAsyncResult singleOperation, Exception delayedException) { if (delayedException != null) { this.completionException = delayedException; MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteBatchManagerException(this.TrackingContext.Activity, this.TrackingContext.TrackingId, this.TrackingContext.SystemTracker, "BatchManager.PerformFlushAsyncResult.CompleteSingleOperation", delayedException.ToStringSlim())); } IOThreadScheduler.ScheduleCallbackNoFlow((object s) => singleOperation.CompleteBatch(delayedException), null); if (Interlocked.Decrement(ref this.batchedResultsCount) == 0) { base.Complete(false, this.completionException); } }
private BatchManager <TItem> .PerformFlushAsyncResult BeginFlush(TrackingContext trackingContext, TimeSpan closeTimeout, AsyncCallback callback, object state) { this.isTimerSet = false; if (this.pendingBatchSize == this.batchOverheadSize) { return(null); } List <BatchManager <TItem> .BatchedObjectsAsyncResult> batchedObjectsAsyncResults = new List <BatchManager <TItem> .BatchedObjectsAsyncResult>(); TimeSpan remainingTime = closeTimeout; int num = 0; while (this.batchedResults.Count > 0) { BatchManager <TItem> .BatchedObjectsAsyncResult batchedObjectsAsyncResult = this.batchedResults.Peek(); int batchSize = batchedObjectsAsyncResult.BatchSize; if (batchedObjectsAsyncResult.RemainingTime > TimeSpan.Zero) { if ((long)(num + batchSize) > this.maximumBatchSize) { break; } if (batchedObjectsAsyncResult.RemainingTime < remainingTime) { remainingTime = batchedObjectsAsyncResult.RemainingTime; } batchedObjectsAsyncResults.Add(batchedObjectsAsyncResult); num = num + batchSize; this.batchedResults.Dequeue(); } else { ActionItem.Schedule((object s) => batchedObjectsAsyncResult.CompleteBatch(new TimeoutException()), null); BatchManager <TItem> batchManager = this; batchManager.pendingBatchSize = batchManager.pendingBatchSize - batchSize; this.batchedResults.Dequeue(); } } BatchManager <TItem> batchManager1 = this; batchManager1.pendingBatchSize = batchManager1.pendingBatchSize - num; if (this.pendingBatchSize > this.batchOverheadSize) { this.SetFlushTimer((long)this.pendingBatchSize >= this.flushThreshold); } if (batchedObjectsAsyncResults.Count <= 0) { return(null); } return(new BatchManager <TItem> .PerformFlushAsyncResult(trackingContext, this, batchedObjectsAsyncResults, null, remainingTime, callback, state)); }
protected override void OnAbort() { if (this.flushTimer != null) { this.flushTimer.Cancel(); } lock (this.syncLock) { foreach (BatchManager <TItem> .BatchedObjectsAsyncResult batchedResult in this.batchedResults) { BatchManager <TItem> .BatchedObjectsAsyncResult batchedObjectsAsyncResult = batchedResult; ActionItem.Schedule((object s) => batchedObjectsAsyncResult.CompleteBatch(new CommunicationObjectAbortedException(SRClient.BatchManagerAborted)), null); } this.batchedResults.Clear(); this.pendingBatchSize = 0; } }