Alex
Alex

Reputation: 11137

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)

Upvotes: 2

Views: 198

Answers (2)

František Žiačik
František Žiačik

Reputation: 7612

You can use AppDomain.UnhandledException event.

Upvotes: 3

vale4674
vale4674

Reputation: 4271

Well. You should do it in a try-catch-finally block then.

Final block is what happens last when you catch an exception. Example

Upvotes: 0

Related Questions