2010-03-09 78 views
2

我正在开发具有自定义动画的Silverlight应用程序。我想每1毫秒更新一次变量animationCounter,以便在一秒钟内的值为1000.我试过DispatcherTimer和System.Threading.Timer。这种方式:Silverlight计时器问题

DispatcherTimer timer = new DispatcherTimer(); (...) 
timer.Interval = new TimeSpan(0, 0, 0, 0, 1); 
timer.Tick += new EventHandler(timer_Tick); (...) 

(...)

void timer_Tick(object sender, EventArgs e) 
{ 
     animationCounter++; 
     Dispatcher.BeginInvoke(() => txtAnimationCounter.Text = animationCounter.ToString()); 
} 

与System.Threading.Timer

System.Threading timer = null; 
timer = new System.Threading.Timer(UpdateAnimationCounter, 0, 1); 

void UpdateAnimationCounter(object state) 
{ 
       animationCounter++; 
     Dispatcher.BeginInvoke(() => txtAnimationCounter.Text = animationCounter.ToString()); 
} 

他们两个都设置约100 AnimationCounter在一秒钟。应该是1000.我不知道为什么。有什么我失踪了吗?

感谢

回答

3

文件应说明计时器不具备的1ms的分辨率,但最少10ms的;)它没有tseem来。无论如何,最小定时器分辨率大约是10毫秒......所以这是他们触发的最小时间间隔。

为什么heck(对不起)你需要1ms吗?听起来对我毫无用处。动画应该可以,每秒大约25到60次更新 - 剩下的眼睛无法看到。

+0

我也没有发现任何文档说明10毫秒的分辨率,但其他一些网站暗示。 – 2010-03-09 11:36:36

+0

谢谢。我不知道。是的,我认为10毫秒的分辨率应该可以。我需要这个值来同步启动一些动画事件。 – jose 2010-03-09 11:39:11