Usually, I will just use Environment.Exit(code)
to exit an application. (Usually through a button click.) But I would like to know is it the proper way to exit, ie, releasing memory etc etc...
问题:
回答1:
Just Close()
all active/existing forms and the application should exit.
回答2:
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.
回答3:
Application.Exit
End
will work like a charm The "END" immediately terminates further execution while "Application.Exit" closes all forms and calls.
Best regrads,
回答4:
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.
回答5:
The following code is used in Visual Basic when prompting a user to exit the application:
Dim D As String
D = MsgBox("Are you sure you want to exit?", vbYesNo+vbQuestion,"Thanking You")
If D = vbYes Then
Unload Me
Else
Exit Sub
End If
End
End Sub
回答6:
me.close()
You should try this. I guess it will work.