超时发生后如何处理NotifyIcon(C#)

时间:2011-06-26 14:24:53

标签: c# .net windows

我有一个NotifyIcon方法,虽然我希望在处理BaloonTip之前发生超时。

private void button1_Click(object sender, EventArgs e)
{
    notifyIcon1.Visible = true;
    notifyIcon1.ShowBalloonTip(30000);
    <wait until timeout occurs>
    notifyIcon1.Dispose();

}

3 个答案:

答案 0 :(得分:3)

notifyIcon1.BalloonTipClosed += delegate {notifyIcon1.Dispose ();};

答案 1 :(得分:1)

我宁愿隐藏NotifyIcon,而不是重新创建/处理它的新实例。

答案 2 :(得分:0)

尝试使用计时器 应该像......:

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);
}

和...

void TimerCallback(object notifyIcon1Obj)
{
    lock (notifyIcon1Obj) 
    {
        NotifyIcon notifyIcon1 = (NotifyIcon)notifyIcon1Obj;
        notifyIcon1.dispose();
        notifyIcon1 = null;
    }
}

HTH