How can I execute a specific chunk of code when my application crashes?
Is there a way that I can execute a specific chunk of code when my application crashes? (i.e. If my application crashes, I would like to safely close some streams)
You can use AppDomain.UnhandledException event.
Well. You should do it in a try-catch-finally block then.
Final block is what happens last when you catch an exception. Example
精彩评论