none
C# destructor/finalize method on process killed RRS feed

  • Question

  • Hi, C# Folks

    If the process of a C# application is killed another process, is the destructor / finalize method get called?

    Thanks,

    Rick 

     

    Monday, September 13, 2010 4:39 PM

Answers

  • No, they do not.  No "user mode" code in the process has a chance to run when a process is terminated.  All finalizers are "user mode" code, as opposed to "kernel mode" code.  That is the whole idea of TerminateProcess: to end the process ASAP.  The kernel will still close its objects like files so that the process should not leak system resources.  Whereas the finalizers might flush such objects, on a TerminateProcess the flushes will not happen so recently written data might be lost in cases where this would not have happened had the finalizers run.

    • Proposed as answer by Shane_B Tuesday, September 14, 2010 2:19 AM
    • Marked as answer by SamAgain Monday, September 20, 2010 9:42 AM
    Monday, September 13, 2010 11:03 PM