c# - Finally Block Not Running? -


ok kind of weird issue , hoping can shed light. have following code:

static void main(string[] args) {     try     {         console.writeline("in try");         throw new encoderfallbackexception();     }     catch (exception)     {         console.writeline("in catch");         throw new abandonedmutexexception();     }         {         console.writeline("in finally");         console.readline();     } } 

now when compile target 3.5(2.0 clr) pop window saying "xxx has stopped working". if click on cancel button run finally, , if wait until done looking , click on close program button run finally.

now interesting , confusing if same thing compiled against 4.0 clicking on cancel button run block , clicking on close program button not.

my question is: why run on 2.0 , not on 4.0 when hitting close program button? repercussions of this?

edit: running command prompt in release mode(built in release mode) on windows 7 32 bit. error message: first result below running on 3.5 hitting close after windows looks issue, second when run on 4.0 , same thing.

alt text

i able reproduce behavior (i didn't exact steps question when reading first time).

one difference can observe in way .net runtime handles unhandled exception. clr 2.0 runs helper called microsoft .net error reporting shim (dw20.exe) whereas clr 4.0 starts windows error reporting (werfault.exe).

i assume 2 have different behavior respect terminating crashing process. werfault.exe kills .net process whereas .net error reporting shim somehow closes application block still executed.

also have @ event viewer: werfault logs application error notifying crashed process terminated:

 application: consoleapplication1.exe framework version: v4.0.30319 description: process terminated due unhandled exception. exception info: system.threading.abandonedmutexexception stack:    @ program.main(system.string[]) 

dw20.exe logs information item event id 1001 event log , not terminate process.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -