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?
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.