vb_n00b

Which is the right way of exiting an application by clicking on an exit button I used the following code but someone is complaining that my application hangs out when he clicks the exit button.

Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click

End

End Sub


Re: Visual Basic Language Correctly exit application

Ronald Ricardo Ramirez Moran

Use the Close method of your form, or the Exit method of Application static object. Example:

Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close() ' Closes the current form, if is the starting form the application exit.

End Sub

or will be:

Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click

Application.Exit() ' This end the current Thread and closes all the forms loaded in the current AppDomain.

End Sub

Regards






Re: Visual Basic Language Correctly exit application

Spidermans_DarkSide

Ronald Ricardo Ramirez Moran wrote:

Use the Close method of your form, or the Exit method of Application static object. Example:

Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close() ' Closes the current form, if is the starting form the application exit.

End Sub

or will be:

Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click

Application.Exit() ' This end the current Thread and closes all the forms loaded in the current AppDomain.

End Sub

Regards

Hi,

Are these the "official" methods

I thought END was the main way or is that only okay for a single FORM project

Regards,

S_DS






Re: Visual Basic Language Correctly exit application

Ronald Ricardo Ramirez Moran

Yes! Because the "End" Command is not available in Visual basic .NET

Regards,






Re: Visual Basic Language Correctly exit application

Spidermans_DarkSide

Ronald Ricardo Ramirez Moran wrote:

Yes! Because the "End" Command is not available in Visual basic .NET

Regards,

Hi,

Oh yes it is!!

I doubt it has been dropped in FRAMEWORK 2.0 or 3.0.

Click this screenshot link.>>

http://i13.photobucket.com/albums/a272/u-might-want-this/End-statement.jpg

Regards,

S_DS






Re: Visual Basic Language Correctly exit application

TaDa

> I thought END was the main way or is that only okay for a single FORM project

Anyone using "End" should be bound, beaten, tared and feathered, IMHO.





Re: Visual Basic Language Correctly exit application

MattyN

TaDa wrote:

> I thought END was the main way or is that only okay for a single FORM project

Anyone using "End" should be bound, beaten, tared and feathered, IMHO.



Interesting view :P Seeing as the keyword "END" appears in many languages and has been doing so for a long time =\





Re: Visual Basic Language Correctly exit application

narasiman

end works some version of the .net i think






Re: Visual Basic Language Correctly exit application

narasiman

me.close()

at the same time

if declare object for the form then we can use the object

for example

dim a as new form1

a.close






Re: Visual Basic Language Correctly exit application

narasiman

me.close is a way

if we declare when form as object then we can use the object

for example

dim a as new form1

a.close






Re: Visual Basic Language Correctly exit application

Spidermans_DarkSide

narasiman wrote:

end works some version of the .net i think

Hi,

If you read the text from my earlier screenshot END requires all other Forms to be closed first, then END closes or quits the last form and application.

Regards,

S_DS






Re: Visual Basic Language Correctly exit application

TaDa

>Interesting view :P Seeing as the keyword "END" appears in many languages and has been doing so for a long time =\

IMO that's the only reason it's still there.





Re: Visual Basic Language Correctly exit application

SJWhiteley

As stated, End is really present for legacy reasons. It shouldn't be used unless you are aware of the ramifications of using it. Specifically, it ends the application abruptly: no dispose or finalize methods will be called, a forms 'closing' event won't fire, etc. - it won't clean up the application.

With better methods for closing down an application, I can't really see any reason to use it. Application.Exit() is the nicest way of shutting down the application.






Re: Visual Basic Language Correctly exit application

MattyN

i've found the errors of my ways and realise i am a noob im sorry love u guys xxx