2011-06-26 20 views
1

我有一個NotifyIcon方法,雖然我想在處理BaloonTip之前發生超時。如何處理NotifyIcon,發生超時後(C#)

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

} 
+0

這裏的問題是如何等待超時,還是你的氣球很快被隱藏起來? –

+0

@ Jan-Peter Vos如何進行超時 –

+0

答案:Thread.Sleep(5000); –

回答

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

+0

錯誤的計時器種類。您不能在線程池線程上處理控件。它也不會編譯。改爲使用System.Windows.Forms.Timer。 –

+0

點數,10X。 –

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

我寧願隱藏NotifyIcon而不是重新創建/配置一個新的實例的。