WPF Application exit code WPF Application exit code wpf wpf

WPF Application exit code


For WPF, try

Application.Current.Shutdown(110);

Note that the application needs to be running as a console app. This answer is the easiest way I know of; the accepted answer looks more difficult.

An easy test to tell if you're running in console mode: call your app from the command line (make sure your code doesn't shut down right away). The main window should be showing. If you can type another command in the console, your app is not running in its context. The command prompt should be locked, waiting for you to close the window.


override the OnExit method, and in the ExitEventArgs you can set that value.

 protected override void OnExit(ExitEventArgs e) {      e.ApplicationExitCode = your_value; }


It works for me with either method (Environment.ExitCode=110 or Environment.Exit(110)). I hope you are calling the program from the console and not from Visual Studio to then check the ExitCode...