Shaitan00 Posted December 20, 2005 Posted December 20, 2005 For starters, I had a tool (App.exe) that was written in C++6, one of the most important aspects was the return codes which indicated where the tool failed. This was really simple to do, I made my MAIN return int and then when I get to failure points I just do "return 1;" or "return 2;", etc... and this would return the correct value. Now I am re-writing the same tool in C# (as a Console Application called App.exe) but the Return Codes are not working. So far no matter what I try it always returns a value of 0x0 no matter where it fails, I have already tried a few different ways (as seen below) and nothing seems to works. try { // DO THE WORK } catch { //Environment.ExitCode = RET_UNKNOWNSTATIONTYPE; //Environment.Exit(RET_UNKNOWNSTATIONTYPE); //return RET_UNKNOWNSTATIONTYPE; } So from the above code you can see I have already tried 3 different approaches, setting the ExitCode, Exiting with an ExitCode, and simply Returning the value (as I used to do with C++6 and worked fine) However, in all 3 cases I get the following (from the debug window) The program '[1704] App.exe' has exited with code 0 (0x0). No matter what I try it never returns with a return code (note that RET_UNKNOWNSTATIONTYPE = 0x00000001;) Any clues, help, or hints would be greatly appreciated. Thanks, Quote
HJB417 Posted December 21, 2005 Posted December 21, 2005 I ran into the same problem 2 years back. The return code was set properly w/o a debugger attached. I just used Environment.Exit. Quote
*Experts* Nerseus Posted December 21, 2005 *Experts* Posted December 21, 2005 I wouldn't trust the output window for the ExitCode. If you test your EXE with a batch job (to test the exit code) or test it otherwise, using the first two examples should work fine. I couldn't get the "return NN;" to work even when Main was declared as returning int. I've used the "Environment.ExitCode = NN;" syntax and it works fine. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.