How to: Get and Set the Application Exit Code

This example shows how to get and set the application exit code.

Application automatically returns an exit code value to the operating system when the application stops running. Exit codes are most often used by applications to communicate the reason they stopped running to the operating system, or to other running applications.

The default exit code value that is returned by Application is 0. You can get the exit code value by handling Exit and inspecting the ApplicationExitCode property:


int exitCode = e.ApplicationExitCode;


You can change the exit code value from the default by setting ApplicationExitCode, or by calling Shutdown:


e.ApplicationExitCode = 11;



Application.Current.Shutdown(11);


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft