views:

557

answers:

2

I am writing a game in which I want to kick off an event for my game main loop, the event has to be fired after a very small interval of time.

DispatcherTimer helped me in implementing that, I came across this article

http://blogs.silverlight.net/blogs/msnow/archive/2008/07/09/storyboard-versus-dispatchertimer-for-animation-and-game-loops.aspx

according to it StoryBoard approach is better then dispatchertimer. This blog is for silverlight, I am still searching in MSDN docs if WPF storyboard is also kicked off on a second thread. Does anyone know if using storyboard timer in WPF has advantages over dispatcher timer.

+1  A: 

I would say that since its coming from an official blog, then it is probably correct, and the advantages are the one's listed in that blog post. That post was written by a Senior SDET Lead on the Web Tools team at Microsoft. So I would have to assume that what he is saying holds merit.

From my research, the reasons the StoryboardTimer is better than the DispatcherTimer is as follows:

  1. The StoryBoard is handled on a separate thread that is not affected by the UI thread which the DispatcherTimer is on.
  2. The DispatcherTimer is a lower resolution timer than the timer behind the Storyboard class, which causes loss in fidelity.
  3. The Storyboard execution is more stable across the different supported OS’s and web browsers.
Aaron M
Aaron --> First of all thanks for replying and showing your interest in this topic.I have no doubt about the correctness of information from MSDN blog, my question is whether same thing applies for wpf also i.e bullet point you listed above if they apply for wpf also?
Signcodeindie
I am assuming that from the post, those bulleted items apply to WPF
Aaron M
+2  A: 

You could also try to use CompositionTarget.Rendering event, just stay away from the StoryBoard. Here are several links about CompositionTarget.Rendering:

How to: Render on a Per Frame Interval Using CompositionTarget

Silverlight CompositionTarget.Rendering Game Loop

Fun With Animation Part 1 - CompositionTarget.Rendering

Milan Nankov