How can I (reasonably) precisely perform an action every N milliseconds?
Posted
by Jon Cage
on Stack Overflow
See other posts from Stack Overflow
or by Jon Cage
Published on 2010-03-25T17:09:12Z
Indexed on
2010/03/25
17:33 UTC
Read the original article
Hit count: 168
I have a machine which uses an NTP client to sync up to internet time so it's system clock should be fairly accurate.
I've got an application which I'm developing which logs data in real time, processes it and then passes it on. What I'd like to do now is output that data every N milliseconds aligned with the system clock. So for example if I wanted to do 20ms intervals, my oututs ought to be something like this:
13:15:05:0000
13:15:05:0020
13:15:05:0040
13:15:05:0060
I've seen suggestions for using the stopwatch class, but that only measures time spans as opposed to looking for specific time stamps. The code to do this is running in it's own thread, so should be a problem if I need to do some relatively blocking calls.
Any suggestions on how to achieve this to a reasonable (close to or better than 1ms precision would be nice) would be very gratefully received.
© Stack Overflow or respective owner