public void ParallelForEachCalculatePrimes() { var primeNumbers = new ConcurrentBag <int>(); Parallel.ForEach(Enumerable.Range(1, MaxNumber), number => { if (IsPrime(number)) { primeNumbers.Add(number); } }); primeNumbers.Consume(consumer); }
public void ParallelForEachCalculatePrimes() { var primeNumbers = new ConcurrentBag <int>(); Parallel.ForEach(Enumerable.Range(1, MaxNumber), number => { if (IsPrime(number)) { primeNumbers.Add(number); } }); primeNumbers.Consume(consumer); }