117

What exactly is a thread exit code in the Output window while debugging? What information it gives me? Is it somehow useful or just an internal stuff which should not bother me?

The thread 0x552c has exited with code 259 (0x103).
The thread 0x4440 has exited with code 0 (0x0).

Is there maybe some sort of list of possible exit codes along with its significance?

3 Answers 3

101

There actually doesn't seem to be a lot of explanation on this subject apparently but the exit codes are supposed to be used to give an indication on how the thread exited, 0 tends to mean that it exited safely whilst anything else tends to mean it didn't exit as expected. But then this exit code can be set in code by yourself to completely overlook this.

The closest link I could find to be useful for more information is this

Quote from above link:

What ever the method of exiting, the integer that you return from your process or thread must be values from 0-255(8bits). A zero value indicates success, while a non zero value indicates failure. Although, you can attempt to return any integer value as an exit code, only the lowest byte of the integer is returned from your process or thread as part of an exit code. The higher order bytes are used by the operating system to convey special information about the process. The exit code is very useful in batch/shell programs which conditionally execute other programs depending on the success or failure of one.


From the Documentation for GetEXitCodeThread

Important The GetExitCodeThread function returns a valid error code defined by the application only after the thread terminates. Therefore, an application should not use STILL_ACTIVE (259) as an error code. If a thread returns STILL_ACTIVE (259) as an error code, applications that test for this value could interpret it to mean that the thread is still running and continue to test for the completion of the thread after the thread has terminated, which could put the application into an infinite loop.


My understanding of all this is that the exit code doesn't matter all that much if you are using threads within your own application for your own application. The exception to this is possibly if you are running a couple of threads at the same time that have a dependency on each other. If there is a requirement for an outside source to read this error code, then you can set it to let other applications know the status of your thread.

6
  • 1
    Is there a way to get rid of it from the Output window? Commented Jan 10, 2014 at 7:49
  • 27
    @ArneEvertsson - If you go into Tools | Options... under the "Debugging\Output Window" area, there is a "Thread Exit Messages" (On|Off) setting.
    – josh poley
    Commented Jul 1, 2014 at 19:13
  • 2
    This can mean that you are using async methods within a synchronous application main thread and not waiting for them to finish. The easiest way to deal with this is to call Wait() on a Task started and returned by another method as shown in this sample: asp.net/web-api/overview/advanced/… RunAsync().Wait(); Commented Aug 25, 2015 at 21:59
  • 1
    @BronDavies thread-pool thread exits with error code 259 even after calling Wait(). Here is my code: static void Main(string[] args) { var t = new Task<object>(() => SomeOp(2)); t.Start(); t.Wait(); } The thing is, Tasks are executed by thread pool threads and based on thread pool's heuristics it might not terminate the thread even after your task has finished. The thread simply returns to pool of thread waiting to get assigned with next task. And that is why the exit code STILL_ACTIVE (259) sounds so intuitive here.
    – RBT
    Commented Feb 14, 2016 at 1:38
  • The article in the link is wrong. There is no requirement that a thread exit code (or a process exit code, for that matter) be only a single byte. Commented Apr 20, 2017 at 2:19
55

As Sayse mentioned, exit code 259 (0x103) has special meaning, in this case the process being debugged is still running.

I saw this a lot with debugging web services, because the thread continues to run after executing each web service call (as it is still listening for further calls).

2
  • 7
    More info.. generally any thread that is owned by the thread pool will exit with 259. See: stackoverflow.com/questions/21632584/…
    – Skrymsli
    Commented Aug 20, 2014 at 23:16
  • I was wondering what this meant, and your answer was exactly what I was seeing while running my C# console app. Thanks! Commented Jun 9, 2015 at 22:21
0

what happened to me is that I have multiple projects in my solution. I meant to debug project 1, however, the project 2 was set as the default starting project. I fixed this by, right click on the project and select "Set as startup project", then running debugging is fine.

1
  • 1
    I don't see debugging messages in Output window as problems. I was just curious what they are, not how to get rid of them. Commented Jun 24, 2015 at 7:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.