WPF Application exit code

前端 未结 6 844
悲&欢浪女
悲&欢浪女 2020-12-17 15:39

I am trying to set and get the application exit code .

I am trying to do something following :

protected override void OnStartup(StartupEventArgs e)
         


        
6条回答
  •  没有蜡笔的小新
    2020-12-17 16:28

    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.

提交回复
热议问题