I have a variety of small C# winforms applications (though this should apply equally to any .NET app) which need to perform a few minor tasks when they are closed.
I have been making use of the .FormClosing
event to do things like write the current settings file and wait for background threads to finish, etc.
Two questions came to mind about this as far as best practices go:
Do I need to stop timers (or similar tasks) when closing a form? Knowing that terminating the app should dispose of the timer, is it a good idea to issue a
timer.Stop()
in the closing of the form? Is it possible once having entered the.FormClosing
method that the timer could trigger again?Should last-minute tasks, such as writing a settings file, be in the
.FormClosing
or.FormClosed
event (or elsewhere) and why?
Sorry for combining these questions but I felt they were related closely enough to warrant a single thread about properly closing a form-based app.