How to dispose of NotifyIcon, after the timeout has occured (C#)
I have a NotifyIcon method, although I would like the timeout to happen, bef开发者_Python百科ore disposing of the BaloonTip.
private void button1_Click(object sender, EventArgs e)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(30000);
<wait until timeout occurs>
notifyIcon1.Dispose();
}
notifyIcon1.BalloonTipClosed += delegate {notifyIcon1.Dispose ();};
I would rather hide the NotifyIcon
instead of recreating/disposing a new instance of it.
Try using a timer.
Should be something like...:
private Timer taskTimer;
private NotifyIcon notifyIcon1;
private void button1_Click(object sender, EventArgs e)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(30000);
taskTimer = new Timer(TimerCallback, notifyIcon1, 30000, System.Threading.Timeout.Infinite);
}
and...
void TimerCallback(object notifyIcon1Obj)
{
lock (notifyIcon1Obj)
{
NotifyIcon notifyIcon1 = (NotifyIcon)notifyIcon1Obj;
notifyIcon1.dispose();
notifyIcon1 = null;
}
}
HTH
精彩评论