0
I have a Windows Form where I use the Notifyicon component.
When running the software the software by Visual Studio and finish running with the stop debug button:
the icon is not removed until I pass the mouse over it:
I’ve tried following the instructions of some stackoverflow questions but none helped me. I’ll leave the title with their links:
Notifyicon remains in Tray Even after application closing but disappears on Mouse Hover
Issue with Notifyicon not disappearing on Winforms App
As requested the code for the question:
Code snippet responsible for controlling Notifyicon compounding :
private bool allowVisible; // ContextMenu's Show command used
private bool allowClose; // ContextMenu's Exit command used
protected override void SetVisibleCore(bool value)
{
if (!allowVisible)
{
value = false;
if (!this.IsHandleCreated) CreateHandle();
}
UpdateBase(value);
}
private void UpdateBase(bool value)
{
if (base.InvokeRequired)
{
var d = new Action<bool>(UpdateBase);
base.Invoke(d, new object[] { value });
}
else
{
base.SetVisibleCore(value);
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (!allowClose)
{
this.Hide();
e.Cancel = true;
}
base.OnFormClosing(e);
}
private void showToolStripMenuItem_Click(object sender, EventArgs e)
{
allowVisible = true;
Show();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
allowClose = true;
Application.Exit();
}
Other things associated:
private void Form1_FormClosed_1(object sender, FormClosedEventArgs e)
{
//Outras coisas sendo finalizadas
notifyIcon1.Visible = false;
notifyIcon1.Dispose();
}
Do not use C#, but as a general rule you have to release it before terminating the application. If the app is breaking the icon will stay even, regardless of the development language. I suggest you put a routine to end the icon component next to the application or form completion routine.
– Leonardo Getulio
I’ve tried something like this before, but for some reason he didn’t go through the component shutdown routine when the program closed. I tried using a method despose and a destructor in the c++style. I will try this approach again because it may have failed due to some deployment error.
– Thiago Soares Mota
Show the code
– Leandro Angelo
I will post today. I have to select the appropriate snippets for being proprietary software.
– Thiago Soares Mota
Add @Leandroangelo
– Thiago Soares Mota
Does this behavior only happen when you’re debugging the code? If so, I don’t think you need to worry
– Leandro Angelo
If I close the application through the task manager too. But yes it is only in these cases.
– Thiago Soares Mota