Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Any reason to use DispatcherTimer over Storyboard?
2 replies. Latest Post by Grey Matter on July 3, 2009.
(3)
frefaln
Member
153 points
74 Posts
03-09-2009 11:37 PM |
I've seen various threads and blogs comparing DispatcherTimer with empty Storyboards. The consensus seems to be that a game loop should be implemented as a Storyboard, since it doesn't execute on the UI thread and utilizes a higher resolution timer. Sounds good to me.
So the question comes to mind, why would I ever use a DispatcherTimer? If I have a dozen or so other timers (not related to the game loop) that aren't critical and can afford to miss their intervals by a bit, am I better off implementing those as DispatcherTimers? Will they use less memory? Do I risk hiccups in the UI if I'm running a bunch of them at once?
Thanks in advance for the enlightenment!
sl.ayer
Participant
848 points
162 Posts
03-10-2009 2:45 AM |
In my experience DispetcherTimer is not very accurate. If you need precision of better the 50ms then it is probably not a good idea to use it. DispetcherTimer should be used if you need for your callback to execute in UI thread.
Not sure about memory use, but I can't see it as a major concern with any timer implementation.
Upd: I have to make a correction to the above statement. The accuracy issue with DispetcherTimer is not due to the timer itself, but rather to the fact that its callback is executed in UI thread. UI thread is throttled accordingly with application MaxFrameRate setting and that introduces error of ~1/(MaxFrameRate*2). For example if MaxFrameRate set to 60 then on average callback will be late for 8ms. The smaller your timer interval is the bigger error is going to be. All of the above applies to storyboard's Completed event since it executes in UI thread as well.
Grey Matter
39 points
108 Posts
07-03-2009 4:14 PM |
I still have some confusions:
1. How can I be sure that MaxFrameRate value will always be 60 for every computer (including portable computers and so forth)? If 60 fps isn't supported on any machine with Silverlight then my game-loop will make unexpected speed and it won't be good at all.
2. Is there any way to get more frequent (than 60/sec), stable, and platform-independent tick ?
I tried to increase MaxFrameRate value but I didn't reached more than 450/sec and again I'm not sure that on another computer it won't give another result.