WPF中使用定时器的注意事项

注意事项

要使用System.Windows.Threading.DispatcherTimer,而不能使用System.Timers.Timer。

原因是WPF是单线程的图形操作。

使用方法

在构造上面有一些不同

_timer = new DispatcherTimer();
_timer.Interval = new TimeSpan(0, 0, 1);   //间隔1秒
_timer.Tick += new EventHandler(Timer_Tick);
_timer.Start();
private void Timer_Tick(object sender, EventArgs e)
{
        dTimer.Stop();//先停止定时器的作用
}

 

你可能感兴趣的:(WPF中使用定时器的注意事项)