Gaurav
Gaurav

Reputation: 753

Simple C# WinForm app shows to have 3 threads in visual studio. Task Manger show 14-16 threads. Why?

I'm creating a very simple WinForm app in C#. With nothing but the form. No other code. When I hit pause and look at the threads window in Visual Studio, i see 3 threads. 1 main thread and 2 worker threads (used for may be GC or JIT)

When I open Task Manager when application is running then I see 14-16 threads for the application. I don't understand what is creating these other threads. Can anyone help?enter image description here

Upvotes: 2

Views: 294

Answers (1)

lesscode
lesscode

Reputation: 6361

Additional worker threads could be there for any number of reasons in a WinForms app, including:

  • Thread pool threads that were used briefly and are waiting for additional work (the thread pool will kill them eventually if nothing is going on)
  • GDI+/DDE will usually create a background thread
  • CLR Finalizer thread

It's likely that most of the threads you're seeing are the first kind.

Tip: If you want to see these threads in the Visual Studio debugger's Threads panel, make sure your project is configured to "Enable native code debugging" (under the Debug tab in Project Settings).

Upvotes: 2

Related Questions