如何手动禁用DispatcherTimer
自动触发事件和触发事件?
答案 0 :(得分:4)
只需在Tick处理程序中调用Stop()
或设置IsEnabled = false
:
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += TimerTick;
timer.Start();
...
private void TimerTick(object sender, EventArgs e)
{
((DispatcherTimer)sender).Stop();
...
}