ParallelOptions.MaxDegreeOfParallelism
和ParallelOptions.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;
}
}