SysTrayIcon disappear

Just starting out? Need help? Post your questions and find answers here.
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

SysTrayIcon disappear

Post by Balmung »

I have a strange bug in my Tool (Windows 10). It creates on startup a SysTrayIcon (simply AddSysTrayIcon(0,WindowID(0),ImageID(0)) ), that works as it should so far. But now some users (my Tool is free for download at the Internet) wrote back to me that this Icon disappears, when they trigger a routine (over a popup menu on the SysTrayIcon) where the Icon get changed ( ChangeSysTrayIcon(0,ImageID(1)) ) and his Tooltip ( SysTrayIconToolTip(0,"some text") ). But not every time, only every 2-3 times and the Tool is still running and if the Tool Window is open it still works, only the Icon disappear.

I already written a code into it, that every 2 seconds check if the Icon still exists ( IsSysTrayIcon(0) ) and if not it is created new, but that did not work for them. Right now i don't know yet if the Icon still exists or add a new fails or if even both are working. The Icon is definitely not longer there, so also not hidden in the hidden symbols area.

The 3 used Icon images itself are included in the programs DataSection and opened with CatchImage() and are never changed, only displayed for the SysTrayIcon.

On my own PC i have no problem at all and can not reproduce that bug, no matter how often i trigger that routine that change the SysTrayIcon and his ToolTip. Because all runs over this SysTrayIcon and the Tool Window is normally hidden, the Users need to shut down the Tool over the Task Manager and start it new. So it is really an annoying bug for this Users and made the Tool near unuseable. But I have no clue why this happens and if this is really a PB Bug and no Windows Bug.

// Moved from "Bugs - Windows" to "Coding questions". I will move it back if it is confirmed to be a bug. (Kiffi)

Edit: yeah, needs more testing to be sure it is a PB Bug. I try if i could write a Testtool and give that to that users and will see if it happen again, than i have some code i could post here.
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: SysTrayIcon disappear

Post by BarryG »

Try to narrow it down to a standalone snippet that shows the problem, and post it here.

The SysTray library is extremely robust and I very much doubt this is a PureBasic bug.
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: SysTrayIcon disappear

Post by Balmung »

Easier said than done, because the most users did not have that problem. First I must see if i could reproduce this problem with a simpler code on that users PCs.
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: SysTrayIcon disappear

Post by BarryG »

The SysTray icon can disappear if the "explorer.exe" process is killed and restarted and you haven't coded it to reappear. Could that be the cause?
Balmung wrote:my Tool is free for download at the Internet
So, can we download it to have a test for you?
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: SysTrayIcon disappear

Post by Balmung »

It only works with a Windows Mixed Reality VR Headset, if you don't have one you can not trigger that problem. And not everyone have this problem, only two right now.

http://wmrtt.baltools.de/dl/WMR_TrayTool_V0.5_Alpha.zip
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: SysTrayIcon disappear

Post by BarryG »

Balmung wrote:It only works with a Windows Mixed Reality VR Headset
And for that reason, I'm out.
User avatar
jacdelad
Addict
Addict
Posts: 1483
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: SysTrayIcon disappear

Post by jacdelad »

I have the same problem with one of my projects. Maybe I can narrow it down to a small code.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: SysTrayIcon disappear

Post by Balmung »

Did it happen to you? Badly i can not reproduce this Bug, only other Users who use my App have this issue.

I will also try to write a small code, but have not the time right now, can take some days.
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: SysTrayIcon disappear

Post by BarryG »

All I know is, one of my app uses 2 x systray icons (one shows 9 different images), and both of them are always visible and never disappear, even when "explorer.exe" (the desktop) is killed and restarted. This is very heavy-weight use of them (most apps only show one systray icon with one non-changing image), and neither of them suddenly disappear for no reason.

Actually, now that I think of it, they did disappear when my app got killed by Windows Defender (or any antivirus) - maybe that's happening to your two users? I had to whitelist my app to stop it being killed and quarantined while it was running. But they never just disappear by themselves due to coding.

Also ask the two users where this is happening if their desktop is being killed and restarted? Maybe they're using tweak tools that restart the desktop and not telling you, and you haven't coded your app to account for this.
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: SysTrayIcon disappear

Post by Balmung »

Like i said, the program is still running and if its window is open the window works without any problem. Only the Tray icon is gone and it seems a issystrayicon()? did not notice it, because than it would be created new, build that in the last update that this two users use now.

If the program would stop working, it would be less weird. But it seams there is no critical error triggered when it disappear. And also in 2 months it never happens here on my PC.

But that Antivirus stuff is a thing that i could ask, that crap shows often the weirdest problems. It is always annoying to search a bug where no bug is because other Software creates that problems. And of course it is often your fault from the users view, but i can not blame them, happens to me often enough too... the obvious is not every time the truth. :x

But I'm happy that the users tell me that bugs, this is often not a matter of course. Over 10 years ago I broken a main feature of a other Tool... it takes 6 months until a User told me about it and that even completely casually. :|
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: SysTrayIcon disappear

Post by BarryG »

Balmung wrote:Like i said, the program is still running
Yep, but if the user is restarting their desktop then the systray icon will disappear. Have you asked if they're doing that? (Note: When I say "restart desktop" I am NOT meaning logging off their PC or restarting it - I'm talking about killing and restarting the "explorer.exe" process). Because the systray icon is directly part of the existing "explorer.exe" process, so if that gets killed/restarted, then the icon will disappear with it - even though your program is still running. This sounds the most likely explanation as to what is happening, but we can't be 100% sure without any program code to see.

Are you able to post your entire source code somewhere (in a zip file) for us to look at? I'm happy to look at it with fresh eyes to see if you overlooked something.
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: SysTrayIcon disappear

Post by Balmung »

I can ask them but it would not make much sense, because the said the only click on that menu entry, it does what it should do and than the Icon disappear. Why should they every time when they do this restarting their desktop?

So far i know when in this case the icons disappears, you should detect this with issystrayicon() and could create it new. And my tool already check ever 2 seconds if the icon is still there and if not it is created new. That didn't match with that. Sounds not logical to me.

But sure, I want to know if they do something others, so i will ask them also for other tools they run. And also about Antivirus Software.

I fear the source code is too long, not well enough written and commented for others. I will first try out a shorter Test program, if I don't find something over that above questions.
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: SysTrayIcon disappear

Post by Balmung »

Ok, i see, i was wrong. If you kill explorer.exe and start it new than my tools icon came not back. So issystrayicon() did not work on that. Is there a other way to test it? Because from all other software the icons are back.
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: SysTrayIcon disappear

Post by Balmung »

Get some answers back. Only Windows Defender, no Tool that do anything with tray icons or restart the Desktop and he use two monitors but only one at ones (he switch with windows key+P between them).
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: SysTrayIcon disappear

Post by BarryG »

IsSysTrayIcon() will only tell you if your icons were created or removed by your app, and NOT if they were destroyed by an external factor like a desktop reset.

Take this amended example from the manual, and run it. While it's running, kill "explorer.exe" and restart it, and then click the ButtonGadget() from the code. The debug output will show non-zero for both, falsely indicating that the systray icons are valid, when in reality they're clearly dead and gone. This is because the code never used RemoveSysTrayIcon() on them.

In other words, it's totally pointless to check IsSysTrayIcon() if your app never uses RemoveSysTrayIcon().

Code: Select all

If OpenWindow(0, 100, 150, 300, 100, "PureBasic - SysTray Example", #PB_Window_SystemMenu)
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    ; .ico format is available only on Windows
    IconName$ = #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"
  CompilerElse
    UsePNGImageDecoder()
    IconName$ = #PB_Compiler_Home + "examples/sources/Data/world.png"
  CompilerEndIf
  
  ButtonGadget(0, 10, 10, 200, 25, "Click to test IsSysTrayIcon()")
  
  AddSysTrayIcon(1, WindowID(0), LoadImage(0, IconName$))
  AddSysTrayIcon(2, WindowID(0), LoadImage(1, IconName$))
  SysTrayIconToolTip(1, "Icon 1")
  SysTrayIconToolTip(2, "Icon 2")
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_SysTray
      If EventType() = #PB_EventType_LeftDoubleClick
        MessageRequester("SysTray", "Left DoubleClick on SysTrayIcon "+Str(EventGadget()),0)
        
        ChangeSysTrayIcon (EventGadget(), LoadImage(0, IconName$))
        SysTrayIconToolTip(EventGadget(), "Changed !")
      EndIf
    ElseIf Event = #PB_Event_Gadget
      Debug IsSysTrayIcon(1)
      Debug IsSysTrayIcon(2)
    EndIf
  Until Event = #PB_Event_CloseWindow
  
EndIf
Post Reply