Server Help

Non-Subspace Related Coding - c# timers

tcsoccerman - Tue Aug 26, 2008 9:29 pm
Post subject: c# timers
what would cause a c# windows timer to slow down?

i'm using a timer to simply keep track of the time on one of my apps, and quite often, but not always, the timer will "lag". as in the intervals are much farther apart then they are supposed to be. the "lag" can be different each time.

could it be that i just have a slow computer(256mb ram)? or should it not matter?

it's important that this timer is at the right speed. any suggestions?
Mine GO BOOM - Tue Aug 26, 2008 10:43 pm
Post subject:
What "timers" are you using? Most timing systems guarantee that they won't be triggered before the time out, but make no guarantee when it will have time to come back. So if another process is running, you have to wait until that process (and any others scheduled ahead of you) finish.

I bet if you set your programmer to "Above Normal" processing priority, the timers will be closer to their timeout period, as it will jump ahead in the CPU scheduler.
Snrrrub - Tue Aug 26, 2008 11:11 pm
Post subject:
How much is the timer drift and what's the timing interval? If the interval is close to the timer precision (which must be documented somewhere), you're likely to see significant drift. You might be able to access the multimedia timers for higher precision events but I'm not sure how one would go about doing that in C#.

Related to what MGB said, the OS time slice impacts the precision of your timer callback. IIRC, the NT kernel series has a time slice of 15ms but it's possible in newer kernels to decreasing the time slice to 1ms using a Win32 API call (which I can't remember off the top of my head) or by running Windows Media Player in the background.

Your RAM should have virtually no impact on timer precision.

-Snrrrub
Mine GO BOOM - Wed Aug 27, 2008 1:08 am
Post subject:
Snrrrub wrote:
You might be able to access the multimedia timers for higher precision events but I'm not sure how one would go about doing that in C#.

High Precision Interval Timer in C#. Give that a try.
tcsoccerman - Wed Aug 27, 2008 4:10 pm
Post subject:
I'm using the one built into the .net framework.

the interval is pretty low, at 1/100 of a second(maintimer.Interval = 10 to be exact).


i'll try the high precision timer first. if that doesn't work, i'll try setting it to 1/10 of a second.
tcsoccerman - Wed Aug 27, 2008 8:55 pm
Post subject:
I just tested it again and it worked fine. The the only difference between this test and the one previous was that the one previous was running just-in-time debugging, and probably other things in it's first run (is still in intermediate language?).

Could that be the cause?
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group