NotifyIcon is not deleted (stays in tray) when application closes
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### .NET version
Microsoft.WindowsDesktop.App 6.0.3 and all previous
### Did it work in .NET Framework?
No
### Did it work in any of the earlier releases of .NET Core or .NET 5+?
Not that I know of
### Issue description
If you create an iNotifyIcon and show it in tray, when application exits the icon stays in tray. Each time you restart app you get another icon and now have 2,3,4... They do disappear when you hover over them after the app exits. This also impacts Visual Studio where icon stays in tray if debugging session is stopped.
### Steps to reproduce
In Form.Designer.vb
Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
'
'NotifyIcon1
'
Me.NotifyIcon1.Icon = CType(resources.GetObject("NotifyIcon1.Icon"),System.Drawing.Icon)
Me.NotifyIcon1.Text = "Some Text"
Me.NotifyIcon1.Visible = true
Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
Ther is a workaround but it should not be necessary, and all steps many not be required.
In Form.VB
Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
Me.NotifyIcon1.Visible = False
Me.NotifyIcon1.Icon.Dispose()
Me.NotifyIcon1.Icon = Nothing
Me.NotifyIcon1.Visible = False
Me.NotifyIcon1.Dispose()
Application.DoEvents()
End Sub
Contributor guide
Assessment
This issue has not been assessed yet.