Reputation: 2098
I get the following error "AsOrdered may only be called on the result of AsParallel, ParallelEnumerable.Range, or ParallelEnumerable.Repeat"
When running the following code
myListofActions.AsParallel().WithDegreeOfParallelism(threadCount)
.AsOrdered().ForAll(x => DoMyTask(x));
this code works fine
myListofActions.AsParallel().AsOrdered().ForAll(x => DoMyTask(x));
Is there a way to set the WithDegreeOfParallelism in this case?
Thanks in advance
Upvotes: 2
Views: 481
Reputation: 37030
Try this:
myListofActions.AsParallel()
.AsOrdered()
.WithDegreeOfParallelism(Math.Min(threadCount, Environment.ProcessorCount))
.ForAll(DoMyTask);
Upvotes: 4