Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. notifyicon doesn't disappear when program crashes

notifyicon doesn't disappear when program crashes

Scheduled Pinned Locked Moved C#
questiontutorial
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    scoroop
    wrote on last edited by
    #1

    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

    A D 2 Replies Last reply
    0
    • S scoroop

      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

      A Offline
      A Offline
      aerosmith2k1
      wrote on last edited by
      #2

      Explicitly referencing and removing the icon from the tray // hide icon from the systray notifyIcon1.Visible = false;

      S 1 Reply Last reply
      0
      • A aerosmith2k1

        Explicitly referencing and removing the icon from the tray // hide icon from the systray notifyIcon1.Visible = false;

        S Offline
        S Offline
        scoroop
        wrote on last edited by
        #3

        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... ;)

        M 1 Reply Last reply
        0
        • S scoroop

          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... ;)

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          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

          S 1 Reply Last reply
          0
          • M mav northwind

            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

            S Offline
            S Offline
            scoroop
            wrote on last edited by
            #5

            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

            M 1 Reply Last reply
            0
            • S scoroop

              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

              M Offline
              M Offline
              mav northwind
              wrote on last edited by
              #6

              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

              S 1 Reply Last reply
              0
              • M mav northwind

                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

                S Offline
                S Offline
                scoroop
                wrote on last edited by
                #7

                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

                S 1 Reply Last reply
                0
                • S scoroop

                  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

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • S scoroop

                    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

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups