/// <summary> /// This worker method handles wrapping a batch of items and fire the user-provided batch handler, and handles cleanup of any uncompleted batch items /// </summary> /// <param name="e">List of items included in the batch</param> /// <returns></returns> private async Task batchProcessor_DoWork(AsyncListProcessorItemEventArgs <List <InternalBatchProcessorItem> > e) { var batch = e.Item; try { //Create a read-only collection to send to the user-provided handler var userBatch = batch.Select(item => new BatchProcessorRequest(item)).ToList(); var readOnlyUserBatch = new ReadOnlyCollection <BatchProcessorRequest>(userBatch); await userBatchProcessorHandler(readOnlyUserBatch); } catch (Exception ex) { TraceQueue.Trace(this, TracingLevel.Warning, "{0} occurred while processing batch: {1}", ex.GetType().Name, ex.Message); } finally { //Force any item left uncompleted into either an exception or default response foreach (var item in batch) { if (!item.Task.IsCompleted) { if (this.UnprocessedItemAction == UnprocessedItemAction.ThrowException) { item.TaskSource.TrySetException(new TaskCanceledException("Task was not processed by batch processor handler")); } else { item.TaskSource.TrySetResult(default(TResponse)); } } } } }
private Task processItem(AsyncListProcessorItemEventArgs <AsyncListTestObject> e) { e.Item.SetResult(true); return(Task.FromResult(true)); }