472,110 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

Application Exit

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
4 10687
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
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
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
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.

Similar topics

1 post views Thread by Guinness Mann | last post: by
3 posts views Thread by John Wildes | last post: by
3 posts views Thread by Marcel Saucier | last post: by
7 posts views Thread by Jay | last post: by
1 post views Thread by =?Utf-8?B?VGFvZ2U=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.