469,271 Members | 1,743 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Application.Exit() vs End

Is there any difference between Application.Exit() and End?
Are there circumstances when I should use one instead of the other?

Matthew
Nov 21 '05 #1
13 12133
"Matthew" <tu*************@alltel.net> schrieb:
Is there any difference between Application.Exit() and End?
Are there circumstances when I should use one instead of the other?


You should try to avoid using both of them...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
> You should try to avoid using both of them...

Thanks for the comment. I have a context menu with a "Exit" option. Is
there an alternative that I am not aware of?

Also, assuming it is one or the other, is there a difference?

Thank,

Matthew
Nov 21 '05 #3
So then how should you close your application?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
"Matthew" <tu*************@alltel.net> schrieb:
Is there any difference between Application.Exit() and End?
Are there circumstances when I should use one instead of the other?


You should try to avoid using both of them...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #4
Chrisotpher

Close the baseform
with me.close

And never use End, that is killing your application not closing it.

I write forever that poweroff is better than End.

Cor
Nov 21 '05 #5
Exit is exit,

End is ending your application direct, it stays in memory however it stops
processesing and stays there probably until powerdown.

Cor
Nov 21 '05 #6
The use of End without a further keyword such as Sub or Class, is not
supported and should not be used. Exit is used to terminate a block of code
for example. In this example anything after Exit Sub would not be executed.

Sub Mine()

'First Statement

Exit Sub

'Second Statement

End Sub

As others suggest You should close all your open resources and then cleanly
exit by either closeing the base form or getting to the end of your Sub Main
if thats how you started the application.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Matthew" <tu*************@alltel.net> wrote in message
news:Oh*************@TK2MSFTNGP11.phx.gbl...
You should try to avoid using both of them...


Thanks for the comment. I have a context menu with a "Exit" option. Is
there an alternative that I am not aware of?

Also, assuming it is one or the other, is there a difference?

Thank,

Matthew

Nov 21 '05 #7
"Matthew" <tu*************@alltel.net> schrieb:
You should try to avoid using both of them...


Thanks for the comment. I have a context menu with a "Exit" option. Is
there an alternative that I am not aware of?


\\\
Me.Close()
///

.... if it is your main form. If there are other forms, you should close
them before closing the main form.

Depending on how your application's message loop was started,
'Application.ExitThread' might be necessary to exit the application after
closing the forms. Make sure you take a look at the 'ApplicationContext'
class too.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #8
> Me.Close() if it is your main form. If there are other forms, you
should close them before closing the main form.


Thanks, I'll use that from now on.

Matthew
Nov 21 '05 #9
> The use of End without a further keyword such as Sub or Class, is not
supported and should not be used. Exit is used to terminate a block of
code for example. In this example anything after Exit Sub would not be
executed.


I'm sure you are right. However, I picked up this nasty habit from the book
Step by Step (version 2003).
Quoting from the end of page 113:
"The End statement stops the program when the user is finished."
In the sample programs provided, that method is used whenever he wants to
stop the program.

Strange stuff...

Matthew
Nov 21 '05 #10
Nak
Hi,
I'm sure you are right. However, I picked up this nasty habit from the
book Step by Step (version 2003).
Quoting from the end of page 113:
"The End statement stops the program when the user is finished."
In the sample programs provided, that method is used whenever he wants to
stop the program.


Christ, it just goes to show that people who teach don't know
everything! I remember reading a book once for VB6 that recommended storing
variables in hidden label controls!! What a b~O_d+G-e!

Nick.
Nov 21 '05 #11
In VB6, you can loop through the forms collection and close each form. I
know that the forms collection doesn't exist in .Net so how is this done.

Mike Ober.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eR****************@TK2MSFTNGP10.phx.gbl...

... if it is your main form. If there are other forms, you should close
them before closing the main form.

Depending on how your application's message loop was started,
'Application.ExitThread' might be necessary to exit the application after
closing the forms. Make sure you take a look at the 'ApplicationContext'
class too.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #12
"Michael D. Ober" <mdo.@.wakeassoc..com> schrieb:
In VB6, you can loop through the forms collection
and close each form. I know that the forms collection
doesn't exist in .Net so how is this done.


You will have to maintain such a collection yourself.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #13
Thanks.

Mike.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...
"Michael D. Ober" <mdo.@.wakeassoc..com> schrieb:
In VB6, you can loop through the forms collection
and close each form. I know that the forms collection
doesn't exist in .Net so how is this done.


You will have to maintain such a collection yourself.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Guinness Mann | last post: by
4 posts views Thread by Bob Day | last post: by
4 posts views Thread by JIM.H. | last post: by
1 post views Thread by =?Utf-8?B?VGFvZ2U=?= | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.