NotifyIcon Problem

  • Thread starter Thread starter james
  • Start date Start date
J

james

My app has a notify Icon, but after the app exits, the Icon is still
visible, and then when I runthe app multiple times I get multiple icons so
that my status bas keeps accumulating them to the point it becomes
un-usable. The only fix I have found is to re-boot. Not a godd solution.
How do I get this to stop happening?

Environment C#, VS.Net 2003, XP Pro

Thanks,

JIM
 
This happens for me to. If you scroll over the icon and away from it,
it will disappear (if the app is no longer running). I believe it is a
bug in the framework.
 
What you can do in your exit() routine is to do a:

WSNotifyIcon.Visible=false;

which will hide and remove the icon from the tray. Now when you run the
app again there will not be several ghosted icons behind.
 
This only work some of the time for me. It does not seem to work when I
have a lot of them, only when I have one or two, not 10

thanks,

JIM
 
Greg,

What is the WS for? Anyway, which exit() routine are you referring to.
..Net Framework does not have exit() that I can find. Anyway, I should point
out that I already do have have NotifyIcon.Visible = false in both my
MainForm_Closing event and in my MainForm.Dispose() but when developing
inside VisualStudio, I do not think these get fired properly when I kill the
app by clicking the STOP button. Any other suggestions?

Thanks,

JIM
 
The WS part is just what I named my NotifyIcon class. I place mine in
the forms exit() method. Set your method up in the this.closing += with
your own custom exit handler. Place the icon hide code in there and see
what happens.

Strange thing is, I've written a few apps that hide the icon and some
that dont' yet the icon always goes away when the application ends.
It's possible there is a bug of some kind in .net.

I have an example of a quick tray app with an xp style ballon tool-tip
and it does not clear out the tray flag yet on this.close() the icon
disappears. The example is at:

http://blog.forwardtechnology.net/gmerideth/articles/194.aspx

Can you post or e-mail me your NotifyIcon setup code section?
 
JIM,

When you click the Stop icon in Visual Studio, it shuts down the entire
application immediately without calling any closing or cleanup code. Rather
try closing your application the way your users would, and then if your
cleanup code makes the tray icon invisible, it should disappear.

Regards
 
Greg,

I downloaded your test tray app, and I find that it does the same thing.
Your icon does not go away either WHEN you kill the app from visual studio.
If you read my message below and try it yourself you will see what I mean

Thanks,

JIM
 
Sean,

When developing a fairly large application it is just not always feasable to
Exit the application gracefully when debugging. For example, often times I
am stepping way down deep into code when I come accross an obvious codeing
error that I simply fix on the fly, kill the app and re-start to check the
fix. Now if I were to continue running the app until I can get back to a
main menu to exit gracefully, for the 300th time in a day I would get very
little done in a day. Also, in my app, the Exit menu fires a bunch of code
that saves state to the registry and sometimes I want to avoid that - plus
it is time consuming.

thanks,

JIM
 
When you hit the stop button, move your mouse over the icon in the System
Tray and it will dissapear.

The stop button kills your app and so does not clean up the NotifyIcons Icon
as you told it to skip everything and just stop.

Would you prefer that when you hit the stop button that it tried to clean
up? In that case there would be no difference to terminating your app
cleanly.
 
If this means that you forces the application to shut down from Visual
Studio, then there is no way you can catch that and clean up the system
tray in your code.

But you don't have to reboot, just move your pointer over the icon and
it will go away.

Regards,
Joakim
 
No, what I would prefer is that the Garbage Collector would recognize that
the app the created the Notify Icon is no longet running and clean up the
Icon. Or at least the Icon should be smart enough to know that its app is
gone and clean itself up. It would be the proper thing to do, but then...

JIM

"Mick Doherty"
 
If the system is smart enough to Dealloc the Icon when you move your mouse
over it then why cant the system be smart enough to remove the icon when the
app is killed. The operating system is aware of this event.

JIM
 
Back
Top