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

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

注意事项

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

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

使用方法

在构造上面有一些不同

_timer = new DispatcherTimer();
_timer.Interval = new TimeSpan(0, 0, 1);   //间隔1秒
_timer.Tick += new EventHandler(TimeUp);
_timer.Start();

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/10657693.html