Aniket
Aniket

Reputation: 1376

Free multiple threads?

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

Answers (4)

sll
sll

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:

enter image description here

See interesting discussion regarding CLR internal threads here: The CLR's internal threads

BTW, notepad is not a .NET Framework application

Upvotes: 6

Lee
Lee

Reputation: 144136

I imagine threads you are seeing are:

  1. The main thread.
  2. The finalizer thread
  3. The In-process debugger helper thread
  4. The concurrent GC thread.

This post details some of the special CLR threads.

Upvotes: 17

abhishek
abhishek

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

driis
driis

Reputation: 164291

The .NET Framework always starts some threads at the beginning of a program:

  1. Your main thread (obviously)
  2. Garbage collection thread
  3. JIT thread.

Upvotes: 3

Related Questions