I've got a script that's chewing through a lot of objects, and sometimes I want to kill it in the middle of the run because I see something going south. Unfortunately, I'm writing to a log file using System.IO.StreamWriter, and whenever I send a Ctrl-C, my log files are stuck open.
Is there any way I can define some kind of handler or exiting function that allows me to gracefully close filehandles and connections that I have open?