假设您有一个LINQ查询
source.AsParallel().Where(expensiveOperation).Select(cheapOperation)
我想在这种情况下Select
也可以并行执行模式运行.也许它只是一个便宜的操作i => i*2
,所以有没有办法在链接方法查询时停止并行执行?
(也许像.AsParallel().Where(expensiveOp).AsSerial?().Select(cheapOp)
?)
您正在寻找的操作是AsSequential
.
source.AsParallel().Where(expensiveOp).AsSequential().Select(cheapOp)