如何检测,当应用程序终止?应用程序

2023-09-02 02:06:15 作者:最萌女汉子

这是一个跟进到我的最初的问题和我想present我的调查结果,并要求更正,想法和见解。我的发现(或者说跨pretations)来自别人的答案给我的previous问题,阅读MSDN .NET 3.5的文档和调试.NET 3.5 code。我希望这将是有价值的人谁不知道像我如何检测一个应用程序终止时。

This is a follow up to my initial question and I would like to present my findings and ask for corrections, ideas and insights. My findings (or rather interpretations) come from people's answers to my previous question, reading MSDN .NET 3.5 documentation and debugging .NET 3.5 code. I hope this will be of value to someone who was wondering like me how to detect when an application terminates.

活动:

System.AppDomain.CurrentDomain.ProcessExit :当提出进程退出,例如:默认的AppDomain 和其他一切被卸载后,[总的运行时间被限制在短短3秒!]。对于WPF中,使用 System.Windows.Application.Exit 代替。对于Windows窗体,运行$ C后 Application.Run(...)的主要方法。

System.AppDomain.CurrentDomain.ProcessExit: raised when process exits, e.g. after the default AppDomain and everything else was unloaded [Total execution time is limited to just 3 seconds!]. For WPF, use System.Windows.Application.Exit instead. For Windows Forms, run code after Application.Run(...) in main method.

System.AppDomain.CurrentDomain.DomainUnload :提出当的AppDomain 不是缺省的AppDomain 卸载,如:运行班,单元测试框架(MbUnit的与TestDriven.NET)时。

System.AppDomain.CurrentDomain.DomainUnload: raised when an AppDomain other than default AppDomain unloads, e.g. when running classes with unit testing frameworks (MbUnit with TestDriven.NET).

System.AppDomain.CurrentDomain.UnhandledException :(如果在默认情况下处理的AppDomain :)上调在任何线程中的任何未处理的异常,无论什么的AppDomain 线程开始,这意味着,这可以作为包罗了所有所有未处理的异常。

System.AppDomain.CurrentDomain.UnhandledException: (if handled in default AppDomain:) raised for any unhandled exception in any thread, no matter what AppDomain the thread started in. This means, this can be used as the catch-all for all unhandled exceptions.

System.Windows.Application.Exit :提出在WPF应用程序(即默认的AppDomain )将会自动退出。覆盖 System.Windows.Application.OnExit 来利用它。

System.Windows.Application.Exit: raised when WPF application (i.e. the default AppDomain) exits gracefully. Override System.Windows.Application.OnExit to take advantage of it.

终结(在C#中的析构函数):当垃圾收集器释放非托管资源的运行。 [总执行时间是有限的!]。

Finalizers (destructors in C#): run when garbage collector frees unmanaged resources. [Total execution time is limited!].

秩序的事件:

WPF应用程序:体面退出

WPF application: graceful exit

System.Windows.Application.Exit System.AppDomain.CurrentDomain.ProcessExit 终结 System.Windows.Application.Exit System.AppDomain.CurrentDomain.ProcessExit Finalizers

WPF应用程序:未处理的异常

WPF application: unhandled exception

System.AppDomain.CurrentDomain.UnhandledException

MbUnit的内部TestDriven.NET运行:通过测试(正常退出)

MbUnit running inside TestDriven.NET: passed test (graceful exit)

System.AppDomain.CurrentDomain.DomainUnload 终结

MbUnit的内部TestDriven.NET运行:失败的测试(未处理的异常是由MbUnit的处理)

MbUnit running inside TestDriven.NET: failed test (unhandled exceptions are handled by MbUnit)

AppDomain.CurrentDomain.DomainUnload 终结

问题:

是我除pretations /结果是否正确? 请你知道的更多细节,我有 离开了呢?例如。何总是 执行时间终结? 请您知道的任何其他事件/ 的想法,我知道的? 在什么事件在那里,什么顺序,他们在其他应用中,如被加注Windows窗体,Web服务,ASP.NET网站等? Are my interpretations/findings correct? Do you know of more details that I have left out? E.g. what is the total execution time for finalizers? Do you know of any other events / ideas that I be aware of? What events are there and what order do they get raised in other applications, e.g. Windows Forms, Web Service, ASP.NET web site, etc?

推荐答案

由ssg31415926的提问/回答提示(这个问题有点颠倒),另外还有Application.SessionEnding其时,当用户注销或关闭时进行调用。它退出事件之前调用。

Prompted by ssg31415926's question/answer (this question is a bit reversed), there's also Application.SessionEnding which is called when the when the user logs off or shuts down. It is called before the Exit event.