Application Exit

B

Bob Day

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
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

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" <[email protected]> escribió en el mensaje | 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
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

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" <[email protected]> escribió en el mensaje | 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
 
T

Tian Min Huang

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/default.asp?url=/library/en-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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top