First, the WPF startup window method.
public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { this.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative); base.OnStartup(e); } }
Two. WPF exit window method
1、Close the current window
this.Close();
2、If the message is captured before the window closes, the window can be canceled.
this.Closing += (s, r) => { };
3、Capture messages after windows are closed
this.Closed += (s, r) => { };
4、Force exit, even if other threads do not end.
Environment.Exit(0);
5、Close the current program, and if no other thread ends, it will not be closed.
System.Windows.Application.Current.Shutdown();
WPFExit summary: Close -> Application.Current.ShutDow () -> Enviroment.Exit (0)
Weak —————————————————————————————–> strong.
Close->When you exit the system, look at the ShutDownModel settings of App.
1、OnLastWindowClose(Default value)
When the last form closes or invokes the Shutdown () method of the Application object, the application closes.
2、OnMainWindowClose
The application closes when the startup form closes or invokes the Shutdown () method of the Application object. (similar to the closing mode of C#’s Windows application)
3、OnExplicitShutdown
The application will be shut down only when the Shutdown () method of the Application object is called.
Examples:
Application.Current.Shutdown(-1); Application.Current.ShutdownMode=ShutdownMode.OnLastWindowClose;
If the system has threads for release, or first release, or call Enviroment.Exit (0)
Forced recovery, shut down the system.