WP7/8 Exit Program

Source: Internet
Author: User

The first method,Call the exit method in XNA. To save system resources, XNA provides a method to exit the game.:

  1. Add a reference to Microsoft. Xna. Framework. Game;
  2. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.