C#中TPL的线程限制数是多少? [英] What is the number of thread limitation of TPL in C#?

查看:74
本文介绍了C#中TPL的线程限制数是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用TPL创建的线程数?



我尝试过的事情:



检查并行度。

I want to know number of threads created using TPL?

What I have tried:

Checked degree of parallelism.

推荐答案

首先这里是链接指向任务并行库的文档。这是一个从这样一个非常通用的问题开始的好地方。您应该检查使用线程池并设置线程池中的最大线程。



First of all here is the link to the docs for the Task Parallel library. This would be a good place to start with such a very generic question. You should probably examine using a threadpool and setting the maximum threads in the thread pool.

// Limit threadpool size
int workerThreads, completionPortThreads;
ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);
workerThreads = 32;
ThreadPool.SetMaxThreads(workerThreads, completionPortThreads);





没有你想要完成的任何细节,编码是什么你正在使用的语言,你正在使用的代码框架,几乎不可能提供任何有意义的答案。



Without any details of what you're trying to accomplish, what coding language you're using, what code framework you're using, it's going to just about be impossible to provide any kind of meaningful answer.


根据文档,任务并行库(TPL) [ ^ ],.. .handles工作的分区, ThreadPool [ ^ ]。



根据ThreadPool [ ^ ]文档,每个进程有一个线程池。从.NET Framework 4开始,进程的线程池的默认大小取决于多个因素,例如虚拟地址空间的大小。进程可以调用 GetMaxThreads [ ^ ]方法确定线程数。可以使用 SetMaxThreads [ ^ ]方法。每个线程使用默认堆栈大小并以默认优先级运行。
According to the documentation, the Task Parallel Library (TPL)[^], "...handles the partitioning of the work, the scheduling of threads on the ThreadPool[^]".

And according toThreadPool[^] documentation, "There is one thread pool per process. Beginning with the .NET Framework 4, the default size of the thread pool for a process depends on several factors, such as the size of the virtual address space. A process can call the GetMaxThreads[^] method to determine the number of threads. The number of threads in the thread pool can be changed by using the SetMaxThreads[^] method. Each thread uses the default stack size and runs at the default priority."


这篇关于C#中TPL的线程限制数是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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