问题描述
我使用单个 Console.ReadLine
语句在 c# 中创建了一个控制台应用程序.在 Visual Studio 中运行此应用程序并进入调试器会在线程窗口中显示 7 个线程(6 个工作线程,一个是 .NET SystemEvents,另一个是 vshost.RunParkingWindow
和主线程).
I created a console app in c# with a single Console.ReadLine
statement. Running this app within Visual Studio and stepping into the debugger shows 7 threads in the thread window (6 worker threads, one is .NET SystemEvents and the other is vshost.RunParkingWindow
and the main thread).
当我在 Visual Studio 之外运行应用程序时,我在 Windows 任务管理器中看到总共 3 个线程.当我期望 1 个线程时,为什么会有这么多?其他人是为了什么而产生的?
When I run the app outside Visual Studio I see a total of 3 threads in Windows task manager. Why so many when I would expect 1 thread? What are the others being spawned for?
推荐答案
如果您正在运行一个 .NET 应用程序,我相信您总是会为 JIT(即时编译器)获得一个线程(主要是休眠)除了你的主线程之外,还有 GC(垃圾收集)线程.
If you're running a .NET application, I believe you always get a thread (mostly sleeping) for the JIT (Just-in-Time compiler) as well as the GC (Garbage Collection) thread, in addition to your main thread.
这篇关于为什么一个基本的单线程 C# 控制台应用程序需要 3 个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!