Share via


How to: Get and Set the Application Exit Code

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

Example

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);