Vra

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)?)

Was dit nuttig?

Oplossing

The operation you're looking for is AsSequential.

source.AsParallel().Where(expensiveOp).AsSequential().Select(cheapOp)
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top