Reputation: 9870
Can someone please explain to me why there are so many threads during debug of my project?
I start my console app (.net 4.5) and I can see there are the following threads:
[8064][Thread Destroyed]
[5528]<No Name>
[9048]<No Name>
[1760]<No Name>
[6836]vshost.RunParkingWindow
[10200].NET SystemEvents
[9692]Main Thread
When I run my Parallel.For with 3 iterations, I get the following threads:
[0]Thread Ended
[10140]<No Name>
[4464]<No Name>
[5332]<No Name>
[6772]vshost.RunParkingWindow
[8660].NET SystemEvents
[6728]Main Thread
[8580]Worker Thread
[9332]Worker Thread
[9168]Worker Thread
[1336]<No Name>
[9464]<No Name>
I assume the 3 Worker Threads are for the 3 iterations in my Parallel.For loop, but: why was a thread destroyed, why are there no name threads, what is RunParkingWindow, why do some thread IDs change eg. Main Thread, and why are there 2 extra No Name threads when I run the Parallel.For?
Upvotes: 5
Views: 1354
Reputation: 28158
The threads with an id of [6772, 8660, 6728, 8580, 9332, 9168] are .Net framework threads I believe.
The no name threads are probably your parallel.for pulling threads from the TPL thread pool. You can change your debug options to show more thread debug information I forget how off the top of my head.
If you're not having a problem with how your threads are being handled, you probably don't need to spend time delving into this, but perhaps you are just researching the framework.
As Alexei pointed out you can set this information in "tools->options->debug->"my code only"
Upvotes: 1
Reputation: 7602
You a running under VIsual studio hosting process. It is meant to enhance your debugging experience. Many of the threads you have listed are from that process.
See: What is the purpose of the Visual Studio Hosting Process?
To disable this feature - Go to Project Properties
> in Debug
tab > uncheck Enable the Visual Studio hosting Process
.
Now your program will debug as its own process and you'll see the right threads. A basic application will start with a main thread, a finalizer thread and a couple of thread pool worker threads. Worker threads will be created and destroyed by the CLR thread pool as it deems fit.
Upvotes: 5