问题描述
我有一个.NET C#/ C ++应用程序,它使用调用退出(0)
(从< stdlib.h中>
)在一个线程以终止。
I have a .NET C# / C++ app which uses a call to exit(0)
(from <stdlib.h>
) in a thread in order to terminate.
奇怪的部分是,在某些情况下,被管理对象的终结器调用退出
,而在其他情况下,他们不叫在后立即叫所有的。
The strange part is, under some circumstances, the finalizers of the managed objects are called right after the call to exit
, and in other circumstances, they are not called at all.
情节pretty的确定 - 应用程序调用来自外部插件的dll一些方法在其生命周期(写在非托管C)
。如果我使用DLL中的一个,该终结总是叫。
如果我使用的DLL B,在终结器永远不会被调用。
The circumstances are pretty deterministic - the app calls some methods from an external plugin dll (written in unmanaged C) during its lifetime.
If I use dll A, the finalizers are always called.
If I use dll B, the finalizers are never called.
什么是终结的情况下退出的预期行为(0)打电话? (如果有任何预期-and documented-行为)
What's the expected behaviour of finalizers in case of an exit(0) call? (if there is any expected -and documented- behaviour)
能否调用外部DLL改变可能会影响进程终止方式的某些全局设置?
Can the calls to the external dlls change some global setting that may impact the way the process is terminated?
推荐答案
据杰夫里氏的书,系统将试图调用终结的进程关闭,但同时存在每个终结(2秒),总-定稿(40秒)超时覆盖该过程中,在此之后,处理被中止。 (当然,确切时间可能现在改变了,这是正确的2.0)
According to Jeff Richter's book, the system does attempt to call finalizers at process shutdown, but there is both a per-finalizer (2s) and a total-finalization (40s) timeout covering this process, after which the process is aborted. (Of course, the exact times might have changed by now, that was right for 2.0)
难道你会看到一个终结这需要2秒以上运行?这将导致定稿停止。
Could you be seeing a finalizer which takes more than 2 seconds to run? That will cause finalisation to cease.
这篇关于.NET - 终结和退出(0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!