1

I'm considering making my own PLinq extension method to provide the feature described in my recent question: Specify task timeout in parallel linq to objects. I'd like to reuse as much existing .Net structure as I can, including any code that may already be specifying a Degree of Parallelism on the PLinq query.

In the below code block I'm specifying a degree of parallelism. Assuming that CustomForAll is a custom PLinq extension method with the same signature as the existing ForAll method, how would I read the degree of parallelism specified on the TSource?

private PictureList FetchPictures(List<Picture> wallResults) 
{                
        wallResults
            .AsParallel()
            .WithDegreeOfParallelism(10)
            .CustomForAll(delegate(Picture p){
4

1 回答 1

2

不幸的是,这不是受支持的操作。PLINQ 的设计方式不允许第三方扩展,而不是恢复到IEnumerable<T>.

并行度存储在ParallelQuery类的私有成员变量中(字段private QuerySettings m_specifiedSettings中的 , int? m_degreeOfParallism)。

您可能会使用反射来提取它,但它是一个内部实现细节,可能会发生变化。

于 2013-08-15T20:57:40.530 回答