I have written a small application which mainly runs in the system tray. The app shows a notifyicon at startup, which works fine. If I start an action from the ContextMenuStrip, the notifyicon should change its icon and change back to original when a process is finished.
I am experiencing a weird behaviour: The icon duplicates itself on the first action and changes its icon properly. Now I am running two notifyicons in the system tray: One of them working properly and changing its icon when the tasks finish, the other one simply stays there and functions - but without an icon change.
I am not sure where the second icon comes from.
This is part of the code I am creating the notifyicon at startup with:
Public Class NotifyIconManager
Private notifyIcon As NotifyIcon
Public Sub New()
notifyIcon = New NotifyIcon
notifyIcon.Icon = My.Resources.icon_normal
notifyIcon.Text = "Ready."
notifyIcon.ContextMenuStrip = Main.notifyicon_ContextMenuStrip
notifyIcon.Visible = True
AddHandler notifyIcon.MouseDoubleClick, AddressOf DoubleClick
End Sub
Public Sub SetNotifyIconUsage()
notifyIcon.Icon = My.Resources.icon_busy
notifyIcon.Text = "Working."
End Sub
Public Sub SetNotifyIconIdle()
notifyIcon.Icon = My.Resources.icon_normal
notifyIcon.Text = "Ready."
End Sub
End Class
I am changing the icon with calling boot.NotifyIconManager.SetNotifyIconUsage()
or boot.NotifyIconManager.SetNotifyIconIdle()
before starting the backgroundworker.
One instance of the class is created in my main startup form:
Public NotifyIconManager As New NotifyIconManager
Now the question is: How can I get rid of the duplicated notifyicon?
I have already tried disposing the notifyicon and creating a new one everytime I want to change the icon, but this creates a duplicate as well. Setting the icon to Nothing and then back to a new icon also does not work for me.