3

I have a Windows Form application with a NotifyIcon. The application runs automatically on system startup, and shows its NotifyIcon and hides the form:

        //InitializeComponent()
        this.SysTrayIcon.Visible = true; //show notifyicon
        this.SysTrayIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SysTrayIcon_MouseClick);
        //...
        this.Visible = false; //hide form

But for some reason, sometimes the NotifyIcon does not show in the notification area (system tray). This happens randomly, sometimes it shows up, sometimes it doesn't, and the application doesn't really do anything at startup, other than load config. The application itself starts up fine; I can see it running in Task Manager.

This issue does not occur when I start the application by running the exe manually, so it leads me to suspect that once in a while, the application loads up before some important resources and silently fails.

It seems that other people have this issue too, but so far nobody has really solved their problem (or my Google-fu isn't strong enough).

Any help would be appreciated, thanks.

Andrew Sun
  • 4,101
  • 6
  • 36
  • 53
  • 1
    Look in the overflow area, it is somewhat random when Windows decides to move the icon there. There's also little guidance in the snippet to see how the Icon property got assigned. It won't show up without one. – Hans Passant Jun 17 '13 at 11:49
  • 1
    No, it's definitely not there (I'm running on Windows 7 too). The Icon property is assigned using a timer, which updates the text of the NotifyIcon and its icon every 1 second. – Andrew Sun Jun 17 '13 at 12:01
  • 1
    That sounds pretty fishy, we can't see that code. Clearly you'll want to test this without the timer. – Hans Passant Jun 17 '13 at 12:04
  • 1
    Hm, I'll try that, but I don't think that would make a difference, as the NotifyIcon shows up most of the time anyways; it only fails once in a while (around ~10% of the time) – Andrew Sun Jun 17 '13 at 12:07

0 Answers0