Silverlight Timer problem
Posted
by jose
on Stack Overflow
See other posts from Stack Overflow
or by jose
Published on 2010-03-09T11:25:13Z
Indexed on
2010/03/09
11:36 UTC
Read the original article
Hit count: 218
Hello,
I am developing a Silverlight application with custom animations. I want to update the variable animationCounter every 1 milissecond, so that in one second the value is 1000. I've tried DispatcherTimer and System.Threading.Timer. this way:
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());
}
with 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());
}
Both of them are setting AnimationCounter around 100 in one second. Should be 1000. I don't know why. Is there anything I'm missing.
Thanks
© Stack Overflow or respective owner