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?
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.
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.
Frefaln
Member
184 Points
110 Posts
Any reason to use DispatcherTimer over Storyboard?
Mar 10, 2009 04:37 AM | LINK
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!
Darren Mart
http://www.checksumlabs.com
sl.ayer
Participant
1693 Points
288 Posts
Re: Any reason to use DispatcherTimer over Storyboard?
Mar 10, 2009 07:45 AM | LINK
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
Member
130 Points
209 Posts
Re: Re: Any reason to use DispatcherTimer over Storyboard?
Jul 03, 2009 09:14 PM | LINK
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.
DispatcherTimer