views:

71

answers:

4

Im creating a system tray application in visual studio 2010, using C#.

When the application starts i create my thread and a system tray icon. THe icon shows, however whenever i mouse over the icon, it disappears ( the application is still running ), and even if i click the button to show all hidden icons, it doesnt display.

However, if i dont try to mouse over on it, then it stays their in the system tray.

Any Thoughts or experience?

Thanks in advance

+1  A: 

This means that tray icon has been removed. That usually happens after process terminates but the tray stays there - it is a windows bug.

So for some reason, your tray icon perhaps "crashes".

Without seeing your code, it would be impossible to comment any further.

Aliostad
A: 

If you are creating the icon object and letting it go out of scope without any reference to it, the next garbage collection will call it's destructor and this will happens.

VirtualBlackFox
+1  A: 

Paste this code into your form class:

    protected override void OnFormClosing(FormClosingEventArgs e) {
        notifyIcon1.Visible = false;
        base.OnFormClosing(e);
    }

This ensures the icon will disappear without lingering in the tray. Now set a breakpoint on that code and find out why your form is closing. Copy and paste the stack trace into your question if you cannot figure out why.

Hans Passant
+1  A: 

Thanks for the answers guys.

Uhh, something i did to fix before so although for those who are perhaps curious.

I initially wasnt using a windows form, and this is when the problem occured. However when i set my app to be a windows form, and just hide the form, and not show it in the taskbar, it worked.

Larry