Reputation: 1376
So I have a simple enough console app:
class Program
{
static void Main(string[] args)
{
Console.ReadKey();
}
}
I've built it with release configuration. When I run it and open task manager, I see it has 4 threads. Why is this happening even though I'm not creating any threads?
This can't possibly be each application. I tried opening notepad and it has just 1 thread. Although it is a native app and my console app is managed.
Any ideas?
Upvotes: 20
Views: 341
Reputation: 62504
These are .NET Framework threads created for an application, you can use Visual Studio 2010 Threads debug window to see which threads belongs to an application under the question.
Just created a basic console application with empty main method and we can see that 8 threads were created:
See interesting discussion regarding CLR internal threads here: The CLR's internal threads
BTW, notepad is not a .NET Framework application
Upvotes: 6
Reputation: 144136
I imagine threads you are seeing are:
This post details some of the special CLR threads.
Upvotes: 17
Reputation: 2992
There is one basic difference between a normal COM application and a Managed Application. This is the Garbage Collection.
Each process has a Finalizer Thread associated with it, such that the Finalizers in your application runs only on that Thread.
So the Threads are : 1. Main Thread (which your application has created) 2. Finalizer Thread (used by garbage collector. 3. JIT Thread (used to JIT code on fly)
The other threads can be SysEvents etc.
Upvotes: 1
Reputation: 164291
The .NET Framework always starts some threads at the beginning of a program:
Upvotes: 3