I work with NotifyIcon too, and there are some problems with this. First, you need to install the icon for NotifyIcon and be sure that you have not installed it. Visibility for anything other than Visibility.Visible.
Then, NotifyIcon is just a shell of the NotifyIcon API, and there is a known issue that it cannot always create. Therefore, when you initialize NotifyIcon , it can throw an exception due to an error in Windows (WinApi returns false if it cannot be created, and in the source code they throw an exception there). When this happens, you can simply recreate NotifyIcon in a loop until it is created.
I also saw a problem once when NotifyIcon was not created in app.xaml as an XAML object, but in code, since I always created it in XAML instead of code. Also now I have imported the entire NotifyIcon project from CodeProject , so that I can debug it inside. So now I create it this way:
<NotifyIcon1:NotifyIcon x:Key="NotifyIcon" x:Name="notifyicon" ToolTipText="" Visibility="Visible" IconSource="/Images/Icons/bulb.ico"/>
This should throw an exception if the icon cannot be created in this part of the code in the NotifyIcon library:
/// <summary> /// Creates the taskbar icon. This message is invoked during initialization, /// if the taskbar is restarted, and whenever the icon is displayed. /// </summary> private void CreateTaskbarIcon() { lock (this) { if (!IsTaskbarIconCreated) { const IconDataMembers members = IconDataMembers.Message | IconDataMembers.Icon | IconDataMembers.Tip; //write initial configuration var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members); if (!status) { throw new Win32Exception("Could not create icon data"); } //set to most recent version SetVersion(); messageSink.Version = (NotifyIconVersion) iconData.VersionOrTimeout; IsTaskbarIconCreated = true; } } }
Either you directly edit the code according to your needs, or try to recreate notifyicon when there is an Exception.
I suppose this will be a problem because it was the same for us, because sometimes after starting Windows, itβs not yet ready to create an icon. If you have another problem, send the code that you use to create notifyicon and the system (XP? 64bit?) On which the problem occurs.