Assume you have a LINQ query like
source.AsParallel().Where(expensiveOperation).Select(cheapOperation)
I suppose in this case Select
also runs in parallel execution mode. Maybe it's just a cheap operation like i => i*2
, so is there a way to stop parallel execution at a point of querying with chained methods?
(maybe like .AsParallel().Where(expensiveOp).AsSerial?().Select(cheapOp)
?)
The operation you're looking for is AsSequential
.
source.AsParallel().Where(expensiveOp).AsSequential().Select(cheapOp)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With