Cags
Contributor
I've always used Application.Exit() as a way of closing down my application. It recently dawned on me however that doing so doesn't appear to call either Dispose, OnClosed or OnClosing (at least a break point doesn't stop in them) of the form which is passed to Application.Run(). Now call me niave, but I always assumed this was the case. Whilst I never realised this untill now I have never appeared to have any ill effects such as memory leaks, now is this through sheer luck or is there another explanation (such as the Disposed method being called, but after the debugger has been detached from the appliction)?
I've recently been starting todo some stuff that involves alot of API calls and I'm worried that I may leave things behind in memory that should have been dealt with. Is there one method that I can put disposal code in that is always likely to be called, or is it simply a case of ensuring I dispose of the form before calling Application.Exit()?
On a side note, is clicking the stop in Visual Studio whilst debugging the same as calling Application.Exit() or does it exit the application in a different manner? In which case similar to my early question, is there anyway to ensure a section of code is ran before the application exits when the stop button is pressed.
I've recently been starting todo some stuff that involves alot of API calls and I'm worried that I may leave things behind in memory that should have been dealt with. Is there one method that I can put disposal code in that is always likely to be called, or is it simply a case of ensuring I dispose of the form before calling Application.Exit()?
On a side note, is clicking the stop in Visual Studio whilst debugging the same as calling Application.Exit() or does it exit the application in a different manner? In which case similar to my early question, is there anyway to ensure a section of code is ran before the application exits when the stop button is pressed.