2

When running a simple GUI WPF app, without using async/await at all. I'm not creating any new threads by Task.Run, but for some reason this is what appreas in the console of Visual Studio:

The thread 0x1058 has exited with code 0 (0x0).
The thread 0x1b0c has exited with code 0 (0x0).
The thread 0x1ae4 has exited with code 0 (0x0).

What are these threads? Who's creating them? If I see that, it means some of the methods I call create new threads, is that right?

user4205580
  • 564
  • 5
  • 25

3 Answers3

2

What are these threads? Who's creating them?

These threads are managed threads that have been created by the CLR and they are used for the execution of your code. Furthermore, when a thread exits with code 0, means that no errors happened.

I'm not creating any new threads by Task.Run

This is not correct. The Task.Run uses the threads that are in the CLR's managed thread pool. It doesn't create any new threads. This is a decision that is taken by the CLR when it is needed.

Christos
  • 53,228
  • 8
  • 76
  • 108
  • In my application I'm currently getting like 10-15 such thread exits, even though I'm not telling any code to run on a backgroud thread (which is what `Task.Run` does, right?). It's a WPF app, and the code is running in an async button_Click method. Does it mean that CLR can decide to run some piece of code on another thread from the thread pool, even though I'm not explicitly telling it to do so? – user4205580 Nov 25 '15 at 19:52
0

As MSDN says:

Typically, WPF applications start with two threads: one for handling rendering and another for managing the UI. The rendering thread effectively runs hidden in the background while the UI thread receives input, handles events, paints the screen, and runs application code. Most applications use a single UI thread, although in some situations it is best to use several. We’ll discuss this with an example later.

StepUp
  • 36,391
  • 15
  • 88
  • 148
0

This is a bug

You can have a look at this

To avoid this you can go to

Tools -->Options-->under the "Debugging\Output Window" area-->Turn off "Thread Exit Messages" setting

Community
  • 1
  • 1
Vivek Saurav
  • 2,235
  • 4
  • 25
  • 46