7

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

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
  • I belive PLINQ is smart and executes the `Where()` together with the `Select()`. So, even when `Select()` is cheap, you probably don't need to force it to be sequential. But you'll have to measure that for yourself. – svick Dec 24 '13 at 00:22

1 Answers1

10

The operation you're looking for is AsSequential.

source.AsParallel().Where(expensiveOp).AsSequential().Select(cheapOp)
Douglas
  • 53,759
  • 13
  • 140
  • 188