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.我不知道为什么。有什么我失踪了吗?
感谢
我也没有发现任何文档说明10毫秒的分辨率,但其他一些网站暗示。 – 2010-03-09 11:36:36
谢谢。我不知道。是的,我认为10毫秒的分辨率应该可以。我需要这个值来同步启动一些动画事件。 – jose 2010-03-09 11:39:11