哪种关闭窗体的方法更合适: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.

  

posted on 2009-09-19 10:09  listenlisten  阅读(1311)  评论(6编辑  收藏  举报

导航