Disappearing system tray icons

I am creating a system tray application in visual studio 2010 using C #.

When the application starts, I create my thread and icon in the system tray. The icon shows, however, whenever I click on the icon, it disappears (the application is still running), and even if I press the button to show all hidden icons, it will not appear.

However, if I do not try to hover over it, it will remain in the taskbar.

Any thoughts or experience?

Thank you in advance


Thanks for the answers to the guys.

Ughh, something I did to fix earlier, although for those who might be curious.

I did not initially use the window shape, and it was then that the problem arose. However, when I install my application as a window shape and just hide the form and not show it on the taskbar, it worked.

+2
source share
4 answers

Paste this code into your form class:

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

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

+3
source

This means that the tray icon has been deleted. This usually happens after the process is completed, but the tray remains there - this is a window error.

For some reason, the icon on your tray may be a "glitch."

Without looking at your code, it would be impossible to comment.

+1
source

If you create an icon object and let it go out of scope without any reference to it, the next garbage collection will call it a destructor, and this will happen.

+1
source

When you restart Windows Explorer, the windows will clear all the icons in the notification area and send a TaskbarCreated broadcast message. One of them should use this message to add the notification icon again.

You can use the following code to listen for the event:

 UINT WM_TaskBarCreated = ::RegisterWindowMessage(L"TaskbarCreated"); 

and using windowproc or MessageHandler to add an icon to the notification area.

0
source

Source: https://habr.com/ru/post/957371/


All Articles