Force NotifyIcon to appear in system tray

2.9k Views Asked by At

I have a NotifyIcon that appears in the system tray and I want to show a balloon tip the first time stuff the application is idle (As suggested here: C# execute code after application.run() ) but the Idle event happens before the Icon appears in the System tray, causing the balloon to not appear. How can I force the NotifyIcon to appear before I call ShowBalloonTip?

2

There are 2 best solutions below

1
On BEST ANSWER

This is a fairly fundamental race, it is another process that takes care of the icon. Windows Explorer. You can't tell when it took care of things. Calling Thread.Sleep(500) after setting Visible = true ought to improve the odds significantly.

Do consider displaying the icon when your program starts.

2
On

Why not set a flag on idle and then check the state of the flag after setting the notify icon to visible:

// Application has become idle
firstTimeIdle = true;

Then:

// Show notify icon
notifyIcon.Visible = true;
if (firstTimeIdle && !shownBalloon)
{
    notifyIcon.ShowBalloonTip(timeout, title, text, icon);
    shownBalloon = true;
}