First, please see my comment to the question. Functionally, there is no such thing as "End".
You've messed up some simple things in your head. The method
Close
is actually
System.Windows.Forms.Form.Close
. It closes the form, which has nothing to do with application. But! — let's take a look at the entry point:
Sub Main()
'...
Dim myMainForm As New SomeFormClass()
'by this call, it is decided which form is main:
Application.Run(myMainForm)
End Sub
The main form is different in one aspect: if it closes, the method
Application.Run
exits. That's it. That's why the application ultimately terminates, as you can see from the code above.
The method
Application.Exit
just exits the application unconditionally; doing some preliminary pre-exit actions, such as disposing of all forms and, hence, all composed objects as required.
Now, the problem is: if the form is not main, you can close it, but you cannot open it again, otherwise you will get the exception you mentioned. So the pattern should be this: if you want to allow the user to hit the close button but want to use this form again later… capture the attempt to close it and hide it instead. This is done by handling the event
FormClosed
or overriding the virtual method
OnFormClosing
, please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing.aspx[
^].
In this articles, pay attention on the usage of the property
Cancel
of the event arguments parameter. You will need to assign
true
to it to prevent default action, that is, the closing.
—SA