Search code examples
vb.netsystem-trayballoon-tip

Balloon tip notifications not clearing from the sys tray?


I have created a VB.Net program that uses the following code to send balloon tip notifications to the systray:

notify = New NotifyIcon
notify.Visible = True
notify.BalloonTipTitle = title
notify.BalloonTipText = body
notify.Icon = SystemIcons.Application
notify.ShowBalloonTip(100000)

However, the icon for this notification remains in the sys tray after the user has closed the application, and there seems to be no simple way to remove it by clicking on it.

How might I dead with this issue?


Solution

  • It's because you are not disposing the NotifyIcon object. Why exactly are you creating it in code in the first place? Unless you have a specific reason not to, you should be adding it to the form in the designer and then just setting properties and calling methods in code. That way, the object will be disposed when your form is. Failing that, you need to dispose it yourself when you're done with it, which means retaining a reference as long as required and calling Dispose explicitly.