zoukankan      html  css  js  c++  java
  • 哪种关闭窗体的方法更合适:Application.Exit 还是 Form.Close?


    参考:

    Application.Exit 是一种强行退出方式,就像 Win32 的 PostQuitMessage()。它意味着放弃所有消息泵,展开调用堆栈,并将执行返回给系统。

    在 Windows(Win32 或 .NET)中关闭应用程序的正确方式是关闭它的主应用程序窗口(例如 Form.Close)。主消息泵结束后依然存在的任何窗口都需要手动关闭。在应用程序退出之前通过调用 Form.Close 或 Form.Dispose 来关闭窗口是清除窗口的良好做法,但这需要您有意识地去做。我们需要记住,.NET Framework 的 OnClosing() 是 Win32 的托管版本的 WM_CLOSE,而非 WM_DESTROY。

    另外,如果您使用 form.Close(),通过处理 OnClosing 或 OnClosed 事件,就可以让您的应用程序清理内容、关闭文件等。如果您通过 Application.Exit 强行退出应用程序,就无法调用这些事件。

    Good Luck!





    --------------------------------------------------

    李森 – listen
    E-mail:  lisencool@gmail.com

    声明:
    这里集中了在WinCEWindows Mobile开发中的一些基本常识。我很乐意和大家分享,也希望大家提出意见,并给我投稿,我会第一时间替您发表并署上您的大名!

    Announce:
    Here collects general knowledge on WinCE and Windows mobile. I 'm very glad to share them with all friends, and also hope you can share your problems and opinions and contribute articles to me to share with others. I'll publish your articles and sign your name at the first time.

      
  • 相关阅读:
    小心使用宏
    常见文件、目录、路径操作函数
    链表法页框的分配和去配
    获取调试符号文件
    Visual C++ Runtime Error 调试
    HEAP: Free Heap block XXXX modified at XXXX after it was freed
    磁盘操作 API
    【转】浅谈大型网站动态应用系统架构 Mr
    jQuery1.3.1 Tab选项卡 Mr
    spring依赖注入思想 Mr
  • 原文地址:https://www.cnblogs.com/Lisen/p/1569866.html
Copyright © 2011-2022 走看看