zoukankan      html  css  js  c++  java
  • WP7/8退出程序

    第一种办法,调用XNA中的退出方法,为了节约系统资源,XNA中提供了退出游戏的方法

    1. 添加对Microsoft.Xna.Framework.Game的引用;
    2. 调用Game.Exit()来退出程序。

    但是请注意,不要使用该方法。因为该方法违反了微软的应用程序验证的规范,将会导致你的程序无法提交到Marketplace中去。

    第二种方法,抛出自定义的Quit异常来退出程序

    在App.xaml.cs文件中的App类添加如下代码:

    private class QuitException : Exception { }
    public static void Quit()
    {
        throw new QuitException();
    }

    在App类的Application_UnhandledException方法中添加代码,使得它看起来如下:

    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();
        }
    }

    方法三:以上两种都通不过MS验证,现在新的方法是:

      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

    对于WP8可以直接使用:

    Application.Current.Terminate();既可以。WP7bi比较麻烦而已!

  • 相关阅读:
    冰思《L.M》
    Delphi 基本语法与操作《转》
    ADO实现单条记录的刷新《转》
    js正则限制input框输入的常用代码《转》
    Delphi 获取汉字的拼音首字母《转》
    baby one more time
    邮件/域名/DNS相关知识
    Visual Studio 2005 正式版(RTM) BT下载地址
    经典爱情十句话
    Asp中使用存储过程代码收集
  • 原文地址:https://www.cnblogs.com/Yukang1989/p/2915591.html
Copyright © 2011-2022 走看看