System.Threading.Timer Interval Issue / framerate

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Hello. I want to use System.Threading.Timer to control when my windows
form is invalidated. I want it to update at 60 frames per second. But,
if I set the Interval of my timer to anything less than 30ms, the
event isn't triggered. That means I am stuck in the neighborhood of 30
frames per second.

The reason why I am doing this at all is because when I tried to
Invalidate my form from with in the OnPaint call, other windows
suddenly don't seem to get updated when needed. I am not sure if this
is because there messages to update are getting thrown out... or
starvation is occuring... or what.

I just want to call my OnPaint 60 times a second... How can I do it?
 
Andy said:
Hello. I want to use System.Threading.Timer to control when my windows
form is invalidated. I want it to update at 60 frames per second. But,
if I set the Interval of my timer to anything less than 30ms, the
event isn't triggered. That means I am stuck in the neighborhood of 30
frames per second.

The reason why I am doing this at all is because when I tried to
Invalidate my form from with in the OnPaint call, other windows
suddenly don't seem to get updated when needed. I am not sure if this
is because there messages to update are getting thrown out... or
starvation is occuring... or what.

I just want to call my OnPaint 60 times a second... How can I do it?

Have the delegate you passed to the timer call Invalidate on the form. Be
sure to synchronize that with the UI thread if the delegate is executing
from a different thread.

BTW, what do you mean when you say:
<quote>
The reason why I am doing this at all is because when I tried to Invalidate
my form from with in the OnPaint call, ...
</quote>

Do you mean that you call Invalidate from within the OnPaint handler that
you registered to the Paint event of the form?

HTH,
 
Hello. I want to use System.Threading.Timer to control when my windows
form is invalidated. I want it to update at 60 frames per second. But,
if I set the Interval of my timer to anything less than 30ms, the
event isn't triggered. That means I am stuck in the neighborhood of 30
frames per second.

What do you mean by "isn't triggered"? The timer should trigger
events anyway, but it might miss a beat now and then.

Note that you can't get below the granularity of a thread time slice
when using any timers to send Window messages, and that's 10 msec for
a monoprocessor or 15.625 msec for a multiprocessor or P4 HT system.
30 msec is way too close for that to be reliable.
I just want to call my OnPaint 60 times a second... How can I do it?

You can't, really. Use DirectX for smooth animation. The Windows
timer and messaging mechanisms are just not suited for any kind of
real-time operation. You'll always get the occasional delays.
 
Christoph Nahr said:
What do you mean by "isn't triggered"? The timer should trigger
events anyway, but it might miss a beat now and then.

Note that you can't get below the granularity of a thread time slice
when using any timers to send Window messages, and that's 10 msec for
a monoprocessor or 15.625 msec for a multiprocessor or P4 HT system.
30 msec is way too close for that to be reliable.


You can't, really. Use DirectX for smooth animation. The Windows
timer and messaging mechanisms are just not suited for any kind of
real-time operation. You'll always get the occasional delays.

Agreed, using a timer is not a good way to do animation if you want to get
60 frames per second or more. You're better off if you roll your own message
loop.

For sample code, check out Graig Andera's excellent managed Direct3D
tutorial:


http://staff.develop.com/candera/weblog2/articleview.aspx/DirectX/Direct3D/01 GameLoop.xml

Regards,
Sami
 
Back
Top