views:

248

answers:

1

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

+3  A: 

Documentation should state that the timers do not have a resolution of 1ms, but of 10ms minimum ;) It does no tseem to. Anyhow, minimal timer resolution is around 10ms... so that is the smallest interval they fire.

Why the heck (sorry) do you need 1ms anyway? Sounds useless to me. An animation should be ok with around 25 - 60 updates per second - the rest the eye can not see anyway.

TomTom
I also found no documentation stating a 10ms resolution, but some other sites hinted at it.
Benny Jobigan
Thank you. I didn't know that. Yes, I think that 10 ms resolution should be OK. I need this value to start some animation event at sync.
jose