Article View: comp.os.ms-windows.programmer.misc
Article #2132Re: Inaccuracy in windows timer?
From: Kim Letkeman
Date: Wed, 18 Nov 1992 17:20
Date: Wed, 18 Nov 1992 17:20
27 lines
1846 bytes
1846 bytes
In article <1992Nov18.113155.165165@dstos3.dsto.gov.au> jav@dstos3.dsto.gov.au writes:
| I realise that the windows timer is only accurate to 18.2 ms, but
| surely the settimer function is able to correct for non-multiple of
| 18.2 ms intervals (obviously not!). If not, then does any Guru out
| there know how I can correct the time to accurately be able to
| sample every sixty seconds?
Page 175 of Petzold, 2nd Edition:
- The time interval you specify in the SetTimer call is always
rounded down to an integral multiple of clock ticks. For
instance, a 1000-msec interval divided by 54.925 msec is
18.207 clock ticks, which is rounded down to 18 clock ticks,
which is really a 989-msec interval.
Your other choice is to code your own message loop to delay until the
next interval is over. You can do a peek message and the usual
processing, including translate and dispatch and in between you can
check the time. When you reach your time, go for it.
Note that no matter what you do, Windows still does cooperative
multi-tasking, so that any one of your samples could be off by more
than a second if some other app held the CPU at the critical moment.
This would not affect the timer interval of course.
--
Kim Letkeman kim@Software.Mitel.COM
Technical Details
Message-ID:
<KIM.92Nov18122028@kim.Software.Mitel.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!utcsri!skule.ecf!torn!nott!cunews!revcan!software.mitel.com!kim!kimReferences:
<1992Nov18.113155.165165@dstos3.dsto.gov.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!skule.ecf!torn!nott!cunews!revcan!software.mitel.com!kim!kim From: kim@Software.Mitel.COM (Kim Letkeman) Newsgroups: comp.os.ms-windows.programmer.misc Subject: Re: Inaccuracy in windows timer? Message-ID: <KIM.92Nov18122028@kim.Software.Mitel.COM> Date: 18 Nov 92 17:20:28 GMT References: <1992Nov18.113155.165165@dstos3.dsto.gov.au> Sender: kim@Software.Mitel.COM Organization: MITEL Public Switching, Kanata, Ontario, Canada Lines: 27 In-reply-to: jav@dstos3.dsto.gov.au's message of 18 Nov 92 17:31:54 GMT