Properly Exiting an application

J

John Wildes

Hello All

I have an application that has one form. I start the application using a
Application.Run(New frmMain) command in Sub Main(). When I exit, the exit
menu Item simply does a Me.Close . It closes and ends the application, and
closes the NotifyIcon I have specified for this application. When I use
Application.Exit it closes the form and ends the application but the
NotifyIcon doesn't remove itself unless you hover a mouse cursor over it.

I guess my question is, am I gaining anything by using the Application.Exit
command rather than using the Me.Close command?

Just a noob wondering.

Thanks
John
 
A

Armin Zingler

John Wildes said:
I have an application that has one form. I start the application
using a Application.Run(New frmMain) command in Sub Main(). When I
exit, the exit menu Item simply does a Me.Close . It closes and ends
the application, and closes the NotifyIcon I have specified for this
application. When I use Application.Exit it closes the form and ends
the application but the NotifyIcon doesn't remove itself unless you
hover a mouse cursor over it.

I guess my question is, am I gaining anything by using the
Application.Exit command rather than using the Me.Close command?

Just a noob wondering.

Application.Exit kills the application right away and events usually
expected when Forms are closed are not raised. The remaining NotifyIcon is a
visible example that resources are not cleaned up very well.
 
H

Herfried K. Wagner [MVP]

* "John Wildes said:
I have an application that has one form. I start the application using a
Application.Run(New frmMain) command in Sub Main(). When I exit, the exit
menu Item simply does a Me.Close . It closes and ends the application, and
closes the NotifyIcon I have specified for this application. When I use
Application.Exit it closes the form and ends the application but the
NotifyIcon doesn't remove itself unless you hover a mouse cursor over
it.

Have a look at the documentation for 'Application.Exit', there you will
learn what 'Exit' does and what 'Exit' doesn't do.
I guess my question is, am I gaining anything by using the Application.Exit
command rather than using the Me.Close command?

It's better to close the forms by calling their 'Close' method and
removing the icon "by hand" (thorugh your own code).
 
S

Scott M.

This situation is analogus to the VB 6.0 "unload Me" vs. "End" where
me.close equates to unload Me and Application.Exit equates to End.

Application.Exit does what it says, it kills the application right then and
there. The form's normal event sequence is abruptly cut off and the form
doesn't get a chance to fully terminate itself as it would if you call
Me.Close.
 

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