TPL - MaxDegreeOfParallelism和MaximumConcurrencyLevel之间的区别

时间:2011-03-08 16:52:53

标签: .net-4.0 task-parallel-library

ParallelOptions.MaxDegreeOfParallelismParallelOptions.TaskScheduler.MaximumConcurrencyLevel之间有什么区别?你什么时候使用?

1 个答案:

答案 0 :(得分:8)

使用反射器,我收集到两者都在EffectiveMaxConcurrencyLevel属性中使用:

internal int EffectiveMaxConcurrencyLevel
{
    get
    {
        int maxDegreeOfParallelism = this.MaxDegreeOfParallelism;
        int maximumConcurrencyLevel = this.EffectiveTaskScheduler.MaximumConcurrencyLevel;
        if ((maximumConcurrencyLevel > 0) && (maximumConcurrencyLevel != 0x7fffffff))
        {
            maxDegreeOfParallelism = (maxDegreeOfParallelism == -1) ? maximumConcurrencyLevel : Math.Min(maximumConcurrencyLevel, maxDegreeOfParallelism);
        }
        return maxDegreeOfParallelism;
    }
}