The problem may be that you are running the code in the debugger. This means that any code occurs after an unhandled exception is thrown because the debugger stops at that point.
If you run the test script from the debugger, then the Dispose() method is called when the runtime clears the mess. Put some marker code in the Dispose () method, which will give you a visible sign that Dipose calls: for example, create a file in some available folders namesd DisposedHasRun.yeah (note that output to the console or MessageBox not an option, because the application quits due to an unhandled exception). When you run the test case outside the debugger, you will see that the file was created.
However, there are times when Dispose will not be called (and finally ). For example, StackOverflow due to infinite recursion will not call Dispose() , because the runtime will cause the application to exit the system as soon as possible. ( ThreadAbortException I think it will behave the same)
source share