I have an application which runs only from the System Tray, it's only purpose is to provide the user with information via Ballon Tips.
It's running well, apart from one minor annoyance. When the application is closed using the Task Manager (as opposed to using the context menu) the icon sticks around in the system tray, until you hover over it, then when another instance is opened you get a second icon sitting beside the first.
My Form Closed event looks like this, it does nothing:
private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
{
ntfyIcon.Visible = false;
ntfyIcon.Icon = null;
ntfyIcon.Visible = false;
ntfyIcon.Dispose();
}
This has been reported on Microsoft Connect and has been closed by Microsoft under Won't Fix
as, apparently, this is what is supposed to happen but I was hoping that somebody had a solution.
I was thinking something along the lines of cleaning the system tray on application open?
Thanks
For me, it works when calling Application.DoEvents()
after settings Icon
to null
and disposing the NotifyIcon
.
private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
{
ntfyIcon.Icon = null;
ntfyIcon.Dispose();
System.Windows.Forms.Application.DoEvents();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With