By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,810 Members | 783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,810 IT Pros & Developers. It's quick & easy.

Application Exit

P: n/a
Using VS 2003, VB.net...

I am confused about the Application.Exit method, where the help states "This
method does not force the application to exit." Aside from the naming
confusion, how do I force the application to exit? See **** below for my
comments/questions in a simple example.

****In Sub Main, the Application.Exit works as expected, other sub main code
is ignored, and when the end sub is reached the application shuts down.
Sub Main
Try
' code
Catch
Application.Exit
End Try
' other Sub Maincode
Call Sub1
end sub

Sub Sub1
Call Sub2
' other Sub1 code
end Sub

**** in sub 2 below, application.exit does not exit the application, instead
it executes without error, but then executes the other Sub2 code, hits the
end sub, then returns to Sub1 and executes the other Sub1 code.
Sub Sub2
Try
' code
Catch
Application.Exit
End Try
' other Sub2 code
End Sub

**** It seems that for the application to exit, you must traverse the call
stack back up to Sub Main and execute Application.Exit in that method, which
Applicaiton.Exit does not automatically do. I know a can create an
exception, and throw it in Sub 2, catch it in sub main, and accomplish
Application.Exit in sub main and exit sub main and I think that would work.
But this seems like a silly way to do it.

How do I exit the application from Sub 2 above? Assume my simple example
above with no forms being displayed.

Thanks!

Bob Day
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hello, Bob:

Application.exit will end the message loop of the form.
See this sample:

'\\\
sub main()
application.run(new form1) 'Ends when form is closed or application.exit (or exitthread) is called.
call (new form1).show
application.run() 'Only ends whith application.exitthread.
'If you close the form, the program will never end.
msgbox("The message loop has ended")
end sub

class form1
'...
sub button1_click(...)
application.exit
end sub
'...
end class
'///

Regards.
"Bob Day" <Bo****@TouchTalk.net> escribió en el mensaje news:%2****************@TK2MSFTNGP10.phx.gbl...
| Using VS 2003, VB.net...
|
| I am confused about the Application.Exit method, where the help states "This
| method does not force the application to exit." Aside from the naming
| confusion, how do I force the application to exit? See **** below for my
| comments/questions in a simple example.
|
| ****In Sub Main, the Application.Exit works as expected, other sub main code
| is ignored, and when the end sub is reached the application shuts down.
| Sub Main
| Try
| ' code
| Catch
| Application.Exit
| End Try
| ' other Sub Maincode
| Call Sub1
| end sub
|
| Sub Sub1
| Call Sub2
| ' other Sub1 code
| end Sub
|
| **** in sub 2 below, application.exit does not exit the application, instead
| it executes without error, but then executes the other Sub2 code, hits the
| end sub, then returns to Sub1 and executes the other Sub1 code.
| Sub Sub2
| Try
| ' code
| Catch
| Application.Exit
| End Try
| ' other Sub2 code
| End Sub
|
| **** It seems that for the application to exit, you must traverse the call
| stack back up to Sub Main and execute Application.Exit in that method, which
| Applicaiton.Exit does not automatically do. I know a can create an
| exception, and throw it in Sub 2, catch it in sub main, and accomplish
| Application.Exit in sub main and exit sub main and I think that would work.
| But this seems like a silly way to do it.
|
| How do I exit the application from Sub 2 above? Assume my simple example
| above with no forms being displayed.
|
| Thanks!
|
| Bob Day

Nov 20 '05 #2

P: n/a
Hello, Bob:

Application.exit will end the message loop of the form.
See this sample:

'\\\
sub main()
application.run(new form1) 'Ends when form is closed or application.exit (or exitthread) is called.
call (new form1).show
application.run() 'Only ends whith application.exitthread.
'If you close the form, the program will never end.
msgbox("The message loop has ended")
end sub

class form1
'...
sub button1_click(...)
application.exit
end sub
'...
end class
'///

Regards.
"Bob Day" <Bo****@TouchTalk.net> escribió en el mensaje news:%2****************@TK2MSFTNGP10.phx.gbl...
| Using VS 2003, VB.net...
|
| I am confused about the Application.Exit method, where the help states "This
| method does not force the application to exit." Aside from the naming
| confusion, how do I force the application to exit? See **** below for my
| comments/questions in a simple example.
|
| ****In Sub Main, the Application.Exit works as expected, other sub main code
| is ignored, and when the end sub is reached the application shuts down.
| Sub Main
| Try
| ' code
| Catch
| Application.Exit
| End Try
| ' other Sub Maincode
| Call Sub1
| end sub
|
| Sub Sub1
| Call Sub2
| ' other Sub1 code
| end Sub
|
| **** in sub 2 below, application.exit does not exit the application, instead
| it executes without error, but then executes the other Sub2 code, hits the
| end sub, then returns to Sub1 and executes the other Sub1 code.
| Sub Sub2
| Try
| ' code
| Catch
| Application.Exit
| End Try
| ' other Sub2 code
| End Sub
|
| **** It seems that for the application to exit, you must traverse the call
| stack back up to Sub Main and execute Application.Exit in that method, which
| Applicaiton.Exit does not automatically do. I know a can create an
| exception, and throw it in Sub 2, catch it in sub main, and accomplish
| Application.Exit in sub main and exit sub main and I think that would work.
| But this seems like a silly way to do it.
|
| How do I exit the application from Sub 2 above? Assume my simple example
| above with no forms being displayed.
|
| Thanks!
|
| Bob Day

Nov 20 '05 #3

P: n/a
Hello Bob,

Thanks for your post. I reviewed your description carefully, and I'd like
to share the following information with you:

Application.Exit method is generally used to terminate a WinForm
application which has message pumps and application windows. According to
your code snippet, it seems to be a console application without graphical
interfaces. If so, you can call Process.Kill method to terminate the
process forcibly.

Process.Kill Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemdiagnosticsprocessclasskilltopic.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #4

P: n/a
Thanks, that was very helpful.
Bob Day

"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:GT****************@cpmsftngxa07.phx.gbl...
Hello Bob,

Thanks for your post. I reviewed your description carefully, and I'd like
to share the following information with you:

Application.Exit method is generally used to terminate a WinForm
application which has message pumps and application windows. According to
your code snippet, it seems to be a console application without graphical
interfaces. If so, you can call Process.Kill method to terminate the
process forcibly.

Process.Kill Method
http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfsystemdiagnosticsprocessclasskilltopic.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.