Tray icon will not go away!

G

george d lake

Hi,
I have an app that runs in the system tray. When I exit the app (from a
button on a form) the app ends but the icon stays in the tray.
Any ideas?

here is the code I use to end the app

Me.Close()

Me.Hide()

m_trayIcon.Icon = Nothing

End
 
M

Mike Bulava

Set the Visable property of the NotifyIcon to false when your application is
closing.. Setting it to Nothing doesn't just make it go away..
 
H

Herfried K. Wagner [MVP]

* "george d lake said:
I have an app that runs in the system tray. When I exit the app (from a
button on a form) the app ends but the icon stays in the tray.
Any ideas?

here is the code I use to end the app

Me.Close()

Me.Hide()

m_trayIcon.Icon = Nothing

Set the icon's 'Visible' property to 'False' before closing the form.

Why do you use 'End' here?!
 
G

george d lake

Ok, I changed it to:

m_trayIcon.Visible = False
End

and iut still stays there. I have to mouseover it in order for it to go
away.
 
S

Steven Van Dalem

Change the order of you statements:
m_trayIcon.Visible = False
m_trayIcon = Nothing
Me.Hide()
Me.Close()

It's not a good idea to put statements after Me.Close(). If you do it that
way, you have to wait for GC to clean up after you, because m_trayIcon has
gone out of scope

Steven
 
G

george d lake

Its part of a function that ends the app when a button is clicked. I do not
want to use the "X" from the form. Is there a better way of doing this?
 
A

Armin Zingler

george d lake said:
Its part of a function that ends the app when a button is clicked. I
do not want to use the "X" from the form. Is there a better way of
doing this?


There are *only* better ways of doing this.

SCNR

(Sorry, I don't write more - Herfried will *g*)
 
H

Herfried K. Wagner [MVP]

* "george d lake said:
Its part of a function that ends the app when a button is clicked. I do not
want to use the "X" from the form. Is there a better way of doing this?

Pass a reference to the form instance and call its 'Close' method.
 
J

Jay B. Harlow [MVP - Outlook]

George,
In addition to the others comments.

If your app a Form that happens to have a system tray icon. Or a System Tray
icon that happens to have a form?

In my app, which happens to be a System Tray icon that happens to have a
Form, I had to explicitly call Dispose on the Component where the NotifyIcon
was located, which indirectly caused Dispose to be called on the NotifyIcon.

Note the NotifyIcon was located in a class derived from Component. This
component was my startup object. It had a Shared Sub Main that created a new
instance of the component, then called Application.Run with no parameters.

Elsewhere in my program I would create an instance of a form and call
ShowDialog to show it, based on a Menu click event, the component owned the
Menu & NotifyIcon...

Hope this helps
Jay
 

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