sometimes, when I use Form.close() when debugging my program, although the form is closed, the application is still running. I noticed this behaviour when using the msgbox function.
I have no thread nor timer running, so what is the best way to close a .NET app? I am using VB.NET.
Thanks
In .Net 1.1 and earlier, Application.Exit was not a wise choice and the MSDN docs specifically recommended against it because all message processing stopped immediately.
In later versions however, calling Application.Exit will result in Form.Close being called on all open forms in the application, thus giving you a chance to clean up after yourself, or even cancel the operation all together.
Form.Close() is use to close an instance of a Form with in .NET application it does not kill the entire application. Application.exit() kills your application.
Application.Exit()
kills your application but there are some instances that it won't close the application.
End
is better than Application.Exit()
.
If you are in a loop (Do While, For, ...) and you call Me.Close()
, you should follow with an Exit command (Exit Do, ...) or a Return()
to force the message processing to terminate properly. I caught programs hanging due to this.
Just put "End" keyword in your code.
Sub Form_Load()
Dim answer As MsgBoxResult
answer = MsgBox("Do you want to quit now?", MsgBoxStyle.YesNo)
If answer = MsgBoxResult.Yes Then
MsgBox("Terminating program")
End
End If
End Sub
Source: Stackoverflow.com