jose
jose

Reputation: 2543

Silverlight Timer problem

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

Upvotes: 2

Views: 928

Answers (1)

TomTom
TomTom

Reputation: 62093

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.

Upvotes: 3

Related Questions