在.Net应用程序中默认创建多少个默认线程? [英] How many defaults threads created by default in .Net application?

查看:76
本文介绍了在.Net应用程序中默认创建多少个默认线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行示例.Net控制台应用程序,只是为了检查在任务管理器中创建的线程数.但是在任务管理器中为以下代码运行的线程数是10?

I am running the sample .Net Console application just to check the number of threads created in the Task Manager. But the no of threads running for the below code in Task Manager is 10?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Testing--";);
        }
    }
}


任何人都可以让我知道任务管理器中的上述代码应运行多少个默认线程吗?


Can anyone let me know how many default threads should run for thr above code in Task Manager?

推荐答案

取决于系统配置以及您是否已从VisualStudion运行它编译后,您可以运行它或对其进行跟踪...如果在Visual Studio中进行逐步跟踪,则正常情况下会出现10个踏步.
Depends on the system configuration and weather you run it from VisualStudion or already compiled, you run it or trace it... In case of a step by step trace from within Visual Studio, 10 treads are normal.


一个用于程序,另一个用于垃圾回收.

根据 Microsoft文档 [ ^ ].,


线程池是在您第一次创建ThreadPool类的实例时创建的.线程池每个可用处理器的默认限制为25个线程,可以使用mscoree.h文件中定义的CorSetMaxThreads更改此限制.每个线程使用默认堆栈大小并以默认优先级运行.每个进程只能有一个操作系统线程池."


CLR可能会在线程池中创建多余的线程,以防万一您需要它们,但是除非您明确实现,否则代码不会在线程上运行.

如果在应用程序运行时观看Visual Studio中的输出"面板,则可以看到正在创建的线程.
One for the program, and one for garbage collection.

According to the Microsoft documentation[^].,


"The thread pool is created the first time you create an instance of the ThreadPool class. The thread pool has a default limit of 25 threads per available processor, which could be changed using CorSetMaxThreads as defined in the mscoree.h file. Each thread uses the default stack size and runs at the default priority. Each process can have only one operating system thread pool."


The CLR may create extra threads for the thread pool just in case you need them, but your code won''t run on them unless you explicitly make it happen.

You can see threads being created if you watch the Output panel in Visual Studio while your app is running.


这篇关于在.Net应用程序中默认创建多少个默认线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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