473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

System.Threading.Timer Interval Issue / framerate

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?
Nov 16 '05 #1
3 3289
"Andy" <so***********@hotmail.com> wrote in message
news:9c**************************@posting.google.c om...
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,
---
Tom Tempelaere
Nov 16 '05 #2
On 19 May 2004 13:18:47 -0700, so***********@hotmail.com (Andy) wrote:
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.
--
http://www.kynosarges.de
Nov 16 '05 #3

"Christoph Nahr" <ch************@kynosarges.de> wrote in message
news:qe********************************@4ax.com...
On 19 May 2004 13:18:47 -0700, so***********@hotmail.com (Andy) wrote:
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.


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/web...20GameLoop.xml

Regards,
Sami
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
1
by: Can Balioglu | last post by:
Hi, I don't know if it's already known but I found a bug in System.Timers.Timer class. The 'Interval' property accepts a double which specifies the interval between two 'Elapsed' events. The...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
2
by: User | last post by:
Hi, What is the best way to release all resources holded by the Timer (myTimer from class System.Timers.Timer)? Is it: 1- myTimer.dispose 2- myTimer.enabled = false 3- myTimer.close
9
by: archana | last post by:
Hi all, I want to know about interval of timer. I am using timer in windows service.I head somewhere that when i set interval property of timer while setting interval, restart time of Pc is...
4
by: Lauren Quantrell | last post by:
I have just put together a vb.net app and now need to provide it to users. This application needs to run the code in a sub every 60 seconds from a Windows Service application. I have the...
8
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.