我想知道,当我运行Parallel.For / ForEach循环时将使用多少个线程 .
我发现,它可以通过MaxDegreeOfParallelism选项进行更改 .
MSDN上的MaxDegreeOfParallelism帮助说(link):
默认情况下,For和ForEach将使用底层调度程序提供的许多线程,因此从默认值更改MaxDegreeOfParallelism仅限制将使用多少并发任务 .
但我不知道调度程序提供了多少个线程 .
How can I find out that?
我可以用9999999运行循环测试它,但是这个测试会显示数字,但不是确定该数字的规则 .
稍后编辑/添加:
我用google搜索了"sheduler max concurrency",我发现(在MSDN - link), TashSheduler
类有 MaximumConcurrencyLevel
属性,并且:
返回表示最大并发级别的整数 . 默认调度程序返回Int32.MaxValue .
That TaskSheduler class is used as "underlying scheduler" for these parallel loops?
1 回答
根据MSDN:
查看
ThreadPool
的documentation,它说: