4

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?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
David Klempfner
  • 8,700
  • 20
  • 73
  • 153
  • 3
    What stops you from looking at call-stacks of these threads to know what are they doing? (may need to uncheck "tools->options->debug->"my code only") – Alexei Levenkov Jan 16 '14 at 23:33
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Jan 17 '14 at 00:30

2 Answers2

4

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.

Community
  • 1
  • 1
YK1
  • 7,327
  • 1
  • 21
  • 28
1

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 your 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"

BentOnCoding
  • 27,307
  • 14
  • 64
  • 92
  • I thought the 3 "worker thread" threads were from the parallel.for? I know you don't need to know this stuff, but I'm just interested. – David Klempfner Jan 17 '14 at 00:17