home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / mswindo / programm / misc / 3509 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.5 KB

  1. Path: sparky!uunet!usc!rpi!batcomputer!munnari.oz.au!mel.dit.csiro.au!highett!steveo
  2. From: steveo@mel.dbce.csiro.au (Stephen Oakes)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: Inaccuracy in windows timer?
  5. Message-ID: <576@highett.mel.dbce.csiro.au>
  6. Date: 18 Nov 92 05:05:47 GMT
  7. References: <1992Nov18.113155.165165@dstos3.dsto.gov.au>
  8. Organization: CSIRO, Div. Building Constr. and Eng'ing, Melb., Australia
  9. Lines: 38
  10.  
  11. In article <1992Nov18.113155.165165@dstos3.dsto.gov.au> jav@dstos3.dsto.gov.au writes:
  12. >Windows timer inaccuracy!
  13. >
  14. >I have an application which needs to sample a value every 60 seconds.  I use
  15. >the settimer function with an interval of 60000 to send a message to the
  16. >appropriate window which invokes the relevant member function to do the
  17. >sampling (I'm using Boralnd C++ 3.1 with OWL).  This all works fine except that
  18. >the sampling time actually creeps by about 1 second every thirty minutes.  I
  19. >store the time (obtained using standard C time.h functions from the PC clock)
  20. >in a file with every sample and after thirty minutes or so, the sampling occurs
  21. >one second later in the minute than originally.
  22.  
  23. Never ever *ever* *EVER* rely upon the Windows timer to give you accurate
  24. timing.  There are several issues here.  One of them is that (according
  25. to the docs) you are not even guaranteed that you will get every timer message,
  26. because they are low priority messages, and if one stays in the message queue
  27. long enough (until another one is placed there) Windows will remove the first
  28. one.  Or you might just get a message a few seconds late if Windows is busy
  29. with another app.
  30.  
  31. Also, although the docs say that the parameter passed to SetTimer
  32. is in milliseconds, I wonder if they actually use 1/1024 instead?
  33.  
  34. To avoid the slippage you describe, I think there are three possibilities:
  35.     1. Use SetTimer to send you a message far more frequently (say
  36.        every second) and then read the actual time to determine
  37.        whether you should do the sample.
  38.     2. Similar to the above, except do it in a PeekMessage loop
  39.        instead of using a timer.  This may degrade Windows'
  40.        performance slightly.
  41.     3. I think you can use the DDK to get more accurate timings,
  42.        but I don't know anything about this.  
  43.  
  44. --
  45. | Stephen Oakes      CSIRO Division of Building, Construction and Engineering |
  46. |                    Post Office Box 56, Highett, Victoria, Australia   3190  |
  47. | Internet: steveo@mel.dbce.csiro.au  Tel: +61 3 252 6000 Fax: +61 3 252 6249 |
  48. |_____________________________________________________________________________|
  49.