How to exit an application properly

Just Close() all active/existing forms and the application should exit.


Application.Exit() does the trick too: any forms you have can still cancel this for instance if you want to present a save changes dialog.


Application.Exit
    End

will work like a charm The "END" immediately terminates further execution while "Application.Exit" closes all forms and calls.

Best regrads,


In a console application, just return from the main program, in a UI-Application Close() all active Forms.

Memory from managed objects will be handled by the .NET Framework, you don't need to care about this.

If you use classes which implement IDisposable (like database connections, for example), you should call Dispose() on them when you no longer need them (preferred way: a using-Statement).

If you use such resources globally (like private members in your form), your form should implement the IDisposable pattern to release these resources on the Close()-call. See this article for details.