Possible Duplicate:
Capture console exit C#
When I run my console app and the user closes it by closing the console window, the exit code is 0. How to set specific error code in such cases?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One way is to set the ExitCode to whatever you want at anytime throughout the program and at the end of the program, set it to 0. In my example, if the user closes the console before the application completes, it reports ExitCode -1, otherwise it sets the ExitCode to 0: