What is a thread exit code?
Asked Answered
D

3

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?

Data answered 19/9, 2013 at 6:45 Comment(0)
W
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.

Welcome answered 19/9, 2013 at 6:52 Comment(6)
Is there a way to get rid of it from the Output window?Judsen
@ArneEvertsson - If you go into Tools | Options... under the "Debugging\Output Window" area, there is a "Thread Exit Messages" (On|Off) setting.Emoryemote
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();Donettedoney
@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.Hairtail
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.Drennen
It may be related to this question: link. I got the 259 exit code when trying to build and run a solution, and it wouldn't run. I unchecked Properties>>Debug>>"Enable the Visual Studio hosting process", as in @EatAtJoes answer. I could see MyProject.vshost.exe in the task manager, and i couldn't kill it. Disabling the hosting process and saving the solution got rid of the task in the live processes, and also got rid of the 259 messages, and my solution ran fine.Karoline
K
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).

Kun answered 30/12, 2013 at 10:44 Comment(2)
More info.. generally any thread that is owned by the thread pool will exit with 259. See: #21633084Brucite
I was wondering what this meant, and your answer was exactly what I was seeing while running my C# console app. Thanks!Reticular
R
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.

Robbierobbin answered 22/6, 2015 at 14:46 Comment(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.Data

© 2022 - 2024 — McMap. All rights reserved.