WinForms Application.Exit 不一定退出应用程序
在 MSDN 上,我读到调用 Application.Exit 不必每次都退出.我想知道是什么原因造成的?我的意思是什么时候我可以预期 Application.Exit 不会退出应用程序?
on the MSDN I have read that calling Application.Exit does not have to exit every time. I would like to know what could cause that? I mean when I could expect that Application.Exit will not exit the application?
Application.Exit 会为每个打开的表单调用 FormClosing,并且可以取消此事件.如果任何表单取消了此事件,Application.Exit 将停止而不做任何事情.否则所有表格将被关闭.但是,如果您有任何非后台线程在工作(除了主线程之外),您的应用程序将不会通过 Application.Exit 完成.
Application.Exit will call FormClosing for every opened form, and this event can be cancelled. If any form has cancelled this event, Application.Exit will stop without doing anything. Else all forms will be closed. But, if you have any non-background threads working (in additional to main thread) your application will not be finished by Application.Exit.