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



  • 相关阅读:
    数据库管理
    CodeSmith的运用正在完善中,待续
    各搜索引擎搜索代码
    浏览器本地存储
    QQ在线代码生成
    6组Alpha冲刺4/6
    结对编程作业
    camera相关
    数电、模电相关
    usb协议学习
  • 原文地址:https://www.cnblogs.com/zhibin/p/2379591.html
Copyright © 2011-2022 走看看