zoukankan      html  css  js  c++  java
  • Windows Phone抛出异常退出方法

    抛出异常退出是退出的一种方法   强制抛出一个异常  关闭程序

    首先要做的是在App.xaml.cs页面添加

    private class QuitException : Exception { }

    public static void Quit()

    {

    throw new QuitException();

    }

    在App类的Application_UnhandledException方法中添加代码

    // Code to execute on Unhandled Exceptions

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

    }

    }

    然后确保App.xmal中具有设定了UnhandledException的处理:

    01.UnhandledException="Application_UnhandledException"

    在需要退出的地方调用App.Quit() 就能退出程序了;
    在这里顺便介绍一下重写返回键的方法

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {
    e.Cancel = true;
    if (MessageBox.Show("保存工程??", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
    {
    App.Quit();
    }
    }



  • 相关阅读:
    CF1011B
    CF1011A
    AHOI2009 中国象棋
    jsp九大内置对象
    jsp七大动作指令
    navicat从下载到使用
    javaWeb应用部署结构浅析
    tomcat从下载到使用
    JavaWEB前端向服务器端发送对象
    初学者对Spring MVC的认识
  • 原文地址:https://www.cnblogs.com/zhibin/p/2379591.html
Copyright © 2011-2022 走看看