Someone closes your console, stopping you from doing any cleanup?
Fair enough, production code is unlikely to be running in a cute .NET Console App, but maybe you come into a situation where you at least want to prevent somebody from closing your console window without going through your lovely cleanup routines. This link here will tell you what you can do.
To spread the word and to have a slightly less wordy version (using e.g. already defined delegates), you may also just look here (or in Stackoverflow):
“Handler” is just interested in the close event. It returns a boolean that states whether the given Close-message is handled. If you e.g. are letting your Console App hang around with Console.ReadLine() you better return that the event is not handled yet. That way, whatever routines are in place from .NET to handle the blocking Console-call will also be executed. If you would set handled = true, your App is essentially locked and Windows will ask you to end the process.