Fog Creek Software
Discussion Board

Environment.Exit in .NET doesn't work...

I'm trying to use Environment.Exit to exit my Windows Forms app with a specific exit code, but I can't get it to exit with anything besides 0.  The ExitTest sample from the MSDN documentation does not work.  When I run that sample with a command-line param of 47, it output that it will return 2F, but the debugger reports, "ExitTest.exe' has exited with code 0 (0x0)"


Ted Graham
Friday, May 28, 2004

Have you tried running it without the debugger?

Giampiero De Ciantis
Friday, May 28, 2004

Why aren't you just returning the value out of Main instead? :)

Brad Wilson (
Friday, May 28, 2004


Giampiero is right, I just tried it and it seems to be a issue in the VS.Net debugger that always says it exited with 0x0, if you run your program at a dos prompt and then immediately execute ECHO %ERRORLEVEL% you will see the value is being returned correctly....

Chris Ormerod
Wednesday, June 2, 2004

*  Recent Topics

*  Fog Creek Home