139

While debugging my C# application I have noticed a large amount occurrences of the following sentence:

The thread -- has exited with code 0 (0x0).

The application continues to work and no exception is catched/unhanded.

The application is running on Windows 7 64bit and debugged with x86 platform.

Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
Gionata
  • 1,513
  • 2
  • 11
  • 11

8 Answers8

221

This is just debugging message. You can switch that off by right clicking into the output window and uncheck Thread Exit Messages.

http://msdn.microsoft.com/en-us/library/bs4c1wda.aspx

In addition to program out from your application, the Output window can display the information about:

  • Modules the debugger has loaded or unloaded.

  • Exceptions that are thrown.

  • Processes that exit.

  • Threads that exit.

BlueM
  • 6,523
  • 1
  • 25
  • 30
  • I'm getting these message while running a little game I'm writing in C++ from Visual Studio, and the timing of the appearance of the messages is coinciding with moments when my program freezes for a fraction of a second. I'm not deliberately doing anything with threads in my program at this point, so.. I wonder wtf is going on.. I'm going to try building in release mode and running the program outside of Visual Studio.. – Shavais Sep 09 '22 at 22:49
  • Hmm, I still get the occasional thread-exit freeze-glitch even when built in release mode and run outside of Visual Studio, so I guess it must be something in one of my libraries. – Shavais Sep 09 '22 at 23:04
21

Well, an application may have a lot of threads running in parallel. Some are run by you, the coder, some are run by framework classes (espacially if you are in a GUI environnement).

When a thread has finished its task, it exits and stops to exist. There ie nothing alarming in this and you should not care.

Kek
  • 3,145
  • 2
  • 20
  • 26
  • The threads I've discussed about are not mine (or not belonging to my application). However my application needs to connect to a Linux AIX server which returns with a huge amount of defunct processes. I have not a clear idea about this server works (and which are its tasks) but I suppose that the aforementioned threads could impact server behavior. – Gionata Sep 13 '12 at 21:12
  • Well, maybe the threads actually impact your application, but the message you get tells you they terminate sucessfully. So you could try and find why they are run (Debug menu => windows => threads), but this is normal they end. – Kek Sep 14 '12 at 06:21
  • They end normally but the Linux server defunct processes could be a side-effect of .net framework threads. Maybe the application has various programming errors in multithreading implementation. Is it possible? – Gionata Sep 14 '12 at 08:37
  • I don't know. This linuw server is running .NET? using Mono? What is your problem actually? The defunct processes? – Kek Sep 17 '12 at 07:28
  • Yes, the dufunct processes making crash the Linux Server. – Gionata Sep 17 '12 at 09:26
13

In order to complete BlueM's accepted answer, you can desactivate it here:

Tools > Options > Debugging > General Output Settings > Thread Exit Messages : Off

alphanoch
  • 181
  • 1
  • 8
  • 13
    BlueM's accepted answer actually has a simpler solution: _"You can switch that off by right clicking into the output window and uncheck the thread ended message"_ – Simon MᶜKenzie Jul 26 '17 at 03:37
7

If your application uses threads directly or indirectly (i.e. behind the scenes like in a 3rd-party library) it is absolutely common to have threads terminate after they are done - which is basically what you describe. The debugger shows this message - you can configure the debugger to not display this message if you don't want it.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Yahia
  • 69,653
  • 9
  • 115
  • 144
2

Executing Linq queries can generate extra threads. When I try to execute code that uses Linq query collection in the immediate window it often refuses to run because not enough threads are available to the debugger.

As others have said, for threads to exit when they are finished is perfectly normal.

tonyb
  • 379
  • 2
  • 6
1

The framework creates threads to support each window you create, eg, as when you create a Form and .Show() it. When the windows close, the threads are terminated (ie, they exit).

This is normal behavior. However, if the application is creating threads, and there are a lot of thread exit messages corresponding to these threads (one could tell possibly by the thread's names, by giving them distinct names in the app), then perhaps this is indicative of a problem with the app creating threads when it shouldn't, due to a program logic error.

It would be an interesting followup to have the original poster let us know what s/he discovered regarding the problems with the server crashing. I have a feeling it wouldn't have anything to do with this... but it's hard to tell from the information posted.

JoGusto
  • 923
  • 8
  • 8
-3

Stop this error you have to follow this simple steps

  1. Open Visual Studio
  2. Select option debug from the top
  3. Select Options
  4. In Option Select debugging under debugging select General
  5. In General Select check box "Automatically close the console when debugging stop"
  6. Save it

Then Run the code by using Shortcut key Ctrl+f5

**Other wise it still show error when you run it direct

-5

I have also faced this problem and the solution is:

  1. open Solution Explore
  2. double click on Program.cs file

I added this code again and my program ran accurately:

Application.Run(new PayrollSystem()); 
//File name this code removed by me accidentally.
gouessej
  • 3,640
  • 3
  • 33
  • 67