In c++ there is a function called atexit where you can register functions which should be run when the system exits. Are there any similar events in C#?
UPDATE: The
If you're running a WinForms app you can add a listener to the Application.ApplicationExit event
Application.ApplicationExit