MaximumConcurrencyLevel

MaximumConcurrencyLevel

ParallelOptions.MaxDegreeOfParallelismParallelOptions.TaskScheduler.MaximumConcurrencyLevel有什么区别?您什么时候使用?

最佳答案

使用反射器,我收集到两者都在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;
    }
}

07-27 13:38