The first method,Call the exit method in XNA. To save system resources, XNA provides a method to exit the game.:
- Add a reference to Microsoft. Xna. Framework. Game;
- Call Game. Exit () to Exit the program.
But please note that,Do not use this method. Because this method violates Microsoft's application verification specifications, your program cannot be submitted to the Marketplace.
Method 2,Throw a custom Quit exception to exit the program.:
Add the following code to the App class in the App. xaml. cs file:
private class QuitException : Exception { }public static void Quit(){ throw new QuitException();}
Add code to the Application_UnhandledException method of the App class to make it look as follows:
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e){ if (e.ExceptionObject is QuitException) return; if (System.Diagnostics.Debugger.IsAttached) { // An unhandled exception has occurred; break into the debugger System.Diagnostics.Debugger.Break(); }}
Method 3: The above two methods are not verified by MS. The new method is as follows:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { int count = NavigationService.BackStack.Count(); if (count > 0) { for (int i = 0; i < count; i++) { NavigationService.RemoveBackEntry(); } } base.OnNavigatedTo(e); }
Http://blog.jerrynixon.com/2011/11/mango-sample-exit-application.html
You can use WP8 directly:
Application. Current. Terminate (); yes. WP7bi is troublesome!