public void Process(IEventsSource eventsSource) { var degreeOfConcurrency = CalculateDegreeOfConcurrency(); _eventsCollectionForProcess = new BlockingCollection <Guid>(2 * degreeOfConcurrency); _tasks = Enumerable .Range(0, degreeOfConcurrency) .Select(i => Task.Run(() => ProcessEvents())) .ToArray(); foreach (var @event in _eventsSource.GetEvents()) { _eventsCollectionForProcess.Add(@event); } _eventsCollectionForProcess.CompleteAdding(); Task.WaitAll(_tasks); }
public void Process(IEventsSource eventsSource) { Parallel.ForEach(eventsSource.GetEvents(), ProcessEvents); }