.NET中的多个Parallel.ForEach循环 [英] Multiple Parallel.ForEach loops in .Net

查看:74
本文介绍了.NET中的多个Parallel.ForEach循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.Net进程中,只有一个托管线程池.我们可以通过公共属性根据需要设置最小和最大线程数.

In a .Net process, there is only one managed thread pool. We can set the minimum and maximum thread count as needed via public properties.

在.Net中,我们还有 Parallel.ForEach ,它可以从后台的托管线程池中获取线程.

In .Net, we also have Parallel.ForEach that gets its threads from this managed thread pool under the hood.

Parallel.ForEach 中,我们还可以设置 MaxDegreeOfParallelism 来限制最大线程数.

In Parallel.ForEach we can also set the MaxDegreeOfParallelism to limit the maximum number of threads.

我有两个在parrallel中运行的 Parallel.ForEach .一个将 MaxDegreeOfParallelism 设置为3,另一个将其设置为7.

I have two Parallel.ForEach running in parrallel. One has MaxDegreeOfParallelism set to 3 and the other has set to 7.

我的问题是:我的两个 Parallel.ForEach 循环是否在后台使用相同的线程池.如果是,则 Parallel.ForEach 如何使用 MaxDegreeOfParallelism 限制线程.多少倍 Parallel.ForEach 循环和一个托管线程池可以一起工作吗?如果您可以在深入了解.net核心源代码之前提供高级说明或一些指针,那将真正有帮助.

My question is: Does both my Parallel.ForEach loops use the same thread pool under the hood. If yes, how does Parallel.ForEach limits the threads with MaxDegreeOfParallelism. How multiple Parallel.ForEach loops and one managed thread pool work together? It'll really help if you can provide a high level explanation or some pointers before I peak into the .net core source code.

推荐答案

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆