Parallel.Foreach + yield return?

后端 未结 5 1433
执笔经年
执笔经年 2020-12-16 10:50

I want to process something using parallel loop like this :

public void FillLogs(IEnumerable computers)
{
    Parallel.ForEach(computers, cp         


        
5条回答
  •  渐次进展
    2020-12-16 11:02

    I don't want to be offensive, but maybe there is a lack of understanding. Parallel.ForEach means that the TPL will run the foreach according to the available hardware in several threads. But that means, that ii is possible to do that work in parallel! yield return gives you the opportunity to get some values out of a list (or what-so-ever) and give them back one-by-one as they are needed. It prevents of the need to first find all items matching the condition and then iterate over them. That is indeed a performance advantage, but can't be done in parallel.

提交回复
热议问题