我基本上想要一個調度器計時器對象只能執行一次。DispatcherTimer tick一次
所以我的基本代碼:
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 4);
dispatcherTimer.Start();
然後單擊事件中:
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
this.Visibility = System.Windows.Visibility.Visible;
// Now stop timer execution.. or kill the timer object
}
如何停止計時器或該執行後殺死的對象?
無法垃圾收集得到事件觸發之前擺脫了計時器的? – Cameron 2014-04-29 18:04:13
@Cameron,沒有,因爲計時器現在引用了匿名函數,因此它不能被垃圾收集。 – 2014-04-29 18:11:29
沒錯,但還有其他人提到那個匿名函數嗎?不能*也被收集起來? – Cameron 2014-04-29 18:13:45