notifyicon doesn't disappear when program crashes
-
what i noticed is that when your program crashes or you kill the process etc... (i mean generally situations when appplicaion is being closed in an unnormal way :D) notifyicon remains in system tray area. it disappears as soon as you move mouse cursor over it, but if you don't do it it might be there for ages... :]. so my little question is, how to force application to get rid of it in such case. the point is it's not only about my programs, but generally there are many situations when after emergency closure program leaves icon :). or perhaps we should force system to refresh its tray? but how to do it? any ideas? :) thank you in advance
-
what i noticed is that when your program crashes or you kill the process etc... (i mean generally situations when appplicaion is being closed in an unnormal way :D) notifyicon remains in system tray area. it disappears as soon as you move mouse cursor over it, but if you don't do it it might be there for ages... :]. so my little question is, how to force application to get rid of it in such case. the point is it's not only about my programs, but generally there are many situations when after emergency closure program leaves icon :). or perhaps we should force system to refresh its tray? but how to do it? any ideas? :) thank you in advance
Explicitly referencing and removing the icon from the tray // hide icon from the systray notifyIcon1.Visible = false;
-
Explicitly referencing and removing the icon from the tray // hide icon from the systray notifyIcon1.Visible = false;
-
i know how to hide icon from the tray, but how to do it when crash occurs... literally, i need a place in code :D where this snippet should be or a general way of handling crashes, process kills etc... ;)
You can add an event handler for
AppDomain.UnhandledException
to catch any exception that wasn't handled yet and then remove the icon from the systray. This also means you have to have access to the notifyicon at this place, what might not be desirable at this moment. Regards, mav -
You can add an event handler for
AppDomain.UnhandledException
to catch any exception that wasn't handled yet and then remove the icon from the systray. This also means you have to have access to the notifyicon at this place, what might not be desirable at this moment. Regards, mav -
would that work with killing a process? i think that killing doesn't cause any exceptions, nonetheless icon remains in tray in this case as well... hmmmm :)... anyway i'll test that. thanx
No it won't. When you kill the application with taskmanager there's nothing you can do, no event you receive - nothing at all. But you asked about exceptions, not killing the app. Regards, mav
-
No it won't. When you kill the application with taskmanager there's nothing you can do, no event you receive - nothing at all. But you asked about exceptions, not killing the app. Regards, mav
taskmanager or Process.Kill() function... whatever... i know i didn't ask about that. i mentioned about killing a process but that was not a main point... that's just one of the situations when icon doesn't disappear. it seems that it's some bug in windows. isn't it? -- modified at 18:39 Sunday 8th January, 2006
-
taskmanager or Process.Kill() function... whatever... i know i didn't ask about that. i mentioned about killing a process but that was not a main point... that's just one of the situations when icon doesn't disappear. it seems that it's some bug in windows. isn't it? -- modified at 18:39 Sunday 8th January, 2006
This problem has annoyed me for some time now (in my C++ programs - this problem is language independent). I too think it is a bug in explorer (perhaps an oversight would be a better description). We’ll have to wait for Microsoft to fix this one for us (don’t hold your breath). This code (in C++) shows how easy it would be for MS to fix this problem:
STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); PROCESS_INFORMATION pi; BOOL Ok = CreateProcess( "C:\\WINDOWS\\system32\\Notepad.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); if ( Ok ) { WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); MessageBox(NULL, "Remove icon now!", "Remove icon now!", MB_OK); }
If you run this program it will start "Notepad.exe" and display a message box when it terminates - No matter how this happens (even if you kill it). Explorer wouldn't create the process however - It would get the HANDLE to the process from the HWND passed to the Shell_NotifyIcon function. Steve
-
what i noticed is that when your program crashes or you kill the process etc... (i mean generally situations when appplicaion is being closed in an unnormal way :D) notifyicon remains in system tray area. it disappears as soon as you move mouse cursor over it, but if you don't do it it might be there for ages... :]. so my little question is, how to force application to get rid of it in such case. the point is it's not only about my programs, but generally there are many situations when after emergency closure program leaves icon :). or perhaps we should force system to refresh its tray? but how to do it? any ideas? :) thank you in advance
There's no way to clean this up. If your code is stopped by Kill Process, or any other method, that's it, you don't get the chance to kill your icon. Windows Explorer won't get rid of the icon until the mouse if over it. There's simply no way around this until MS gets around to fixing it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome