Originally Posted by
TheRaven
.Net handles the main() method that is considered to be the primary point of entry the ' Application Object ' and Application.Exit(); basically sends a term signal for this method. The application that contains this application object main() method is the parent or root system of your application. When you exit main the application is terminated and destroyed via garbage collection.
Child objects of the application object are also destroyed, prior to the parent/application object, in reverse order of creation/instantiation.
You should only dispose of child objects that were instantiated by the application object. If you use Application.Exit(); from a child object it is telling the system (.Net) to destroy the entire application object, closing down and exiting your application. When the Application.Exit(); method is executed the termination applies to the system from which it was instantiated regardless of the form or dialog that sends it.
There are numerous examples that utilize this methodology at MSDN in the "How Do I" section of the site. Lots of examples, code, and tutorials as well as videos. Your best bet is to check out anything that involves creating/calling forms from within forms like: splash screens, non-model dialogs; etc.
You start MyApp.
using a button in MyApp that transmits the signal Application.Exit(); (like an EXIT button) closes the entire application and all of its child objects (.dll's, child forms; etc.)
You start MyApp and open a dialog and that dialog has a button that says CLOSE that transmits the signal MyAppDialog.Dispose(); You click this button and it will shut down and exit the dialog and will not shut down and exit MyApp because all you have requested was that the Dialog that belongs to MyAPP be closed and exited.
If your MyAPP Dialog has a button that transmits Application.Exit(); clicking this button will shutdown and exit the entire application not just the dialog. The dispose method is a granular disposal method for destroying objects without closing and exiting the main application.