zoukankan      html  css  js  c++  java
  • WPF的退出

    很多时候,会自己写退出程序的代码。

    比如,先显示登录框(LogIn),成功后隐藏它,并显示一个主窗体(MainWin),或者外部还调用了其他App,当你关闭MainWin不一定会直接退出整个程序的。

    我们可以直接终止相关进程:

      System.Environment.Exit(0);

    当然,你可能还想在退出前做一些什么,比如保存一下缓存数据,清空临时文件,等等操作,就需要这样,

    在项目的 App 条目下增加关闭逻辑:(App.xaml.cs)

        /// <summary>
        /// App.xaml 的交互逻辑
        /// </summary>
        public partial class App : Application
        {
            public App()
            {
                this.Exit += App_Exit;
            }
    
            void App_Exit(object sender, ExitEventArgs e)
            {
                //关闭前的一些交互逻辑,如保存
    
                System.Environment.Exit(0);
    
                //throw new NotImplementedException();
            }
    .........

     类似的还有这个:

     System.Diagnostics.Process.GetCurrentProcess().Kill();
  • 相关阅读:
    HDU 1333 基础数论 暴力
    HDU 1299 基础数论 分解
    HDU 1211 EXGCD
    HDU 3507 单调队列 斜率优化
    博弈
    std:ios::sync_with_stdio(false);
    NBUT[1220] SPY
    nbut1217 Dinner
    poj2236Wireless Network
    ZOJ Problem Set
  • 原文地址:https://www.cnblogs.com/3Tai/p/3793052.html
Copyright © 2011-2022 走看看