I'd like to save data from a console application in its final state when closed. I've figured out how to use serialization to save the data, but not how to make this happen when the application closes.
One method is to set an unmanaged handler to intercept the close command and perform an operation, however once the event handler has been called, GC() has already been run and the managed program is no longer in memory.
Any ideas?
Edit: The essential problem here is that I have an object that listens to a stream for the life of the program. If the program is then closed externally (eg by pushing the x in the corner) then no other code in the Main() method is executed, bypassing the closing serialization code.