private Task <BucketContainer> StartProcessingEventsWithPipeline( IEventReader reader, IProgress <int> progress) { var tcs = new TaskCompletionSource <BucketContainer>(); var thread = new Thread(() => { try { var bucketsList = new ResizableArray <Bucket>(); double processedEventsCount = 0; int bucketCount = 0; foreach (var bucket in reader.GetAllBuckets()) { processedEventsCount += bucket.Events.Length; bucketsList.Add(bucket); _eventProcessor.ProcessBucket(bucketsList.GetArraySegment(), bucketCount); if (reader.TotalEventsCount > 0) { progress.Report((int)Math.Min(processedEventsCount / reader.TotalEventsCount * 100, 100)); } bucketCount++; } progress.Report(100); var buckets = bucketsList.ToArray(); bucketsList = null; var container = new BucketContainer(buckets, reader.FirstTimestamp); _eventProcessor.Complete(container); tcs.SetResult(container); } catch (TaskCanceledException) { tcs.SetCanceled(); } catch (Exception exc) { tcs.SetException(exc); } }); thread.Start(); return(tcs.Task); }