MSDN中SetTimer函数的说明: uElapse [in] Specifies the time-out value, in milliseconds. Windows NT/2000/XP: If uElapse is greater than USER_TIMER_MAXIMUM, the timeout is set to 1.Windows 2000/XP: If uElapse is less than USER_TIMER_MINIMUM, the timeout is set to USER_TIMER_MINIMUM.Windows Server 2003: If uElapse is greater than USER_TIMER_MAXIMUM, the timeout is set to USER_TIMER_MAXIMUM.Windows XP SP2/Windows Server 2003 SP1: If uElapse is less than USER_TIMER_MINIMUM, the timeout is set to USER_TIMER_MINIMUM. If uElapse is greater than USER_TIMER_MAXIMUM, the timeout is set to USER_TIMER_MAXIMUM.此外,SetTimer定时也是很不准的。如果要求较高的精度,可以用CreateWaitableTimer、SetWaitableTimer函数。
TIMER不适合做高精度计时器.
也是这个情况么?如果是, 该怎么样,用其它方法解决。
看看这个,高精度的。
Windows并非实时系统,其中时间精度最小只能10ms(XP下只能15ms)不论是SetTimer定时器,还是Sleep都只能在这个精度以上
不过你可以使用多媒体定时器来实现你的功能,精度可以到1ms的
timeSetTimer
不过要注意进程最多开16个
http://blog.csdn.net/zgl7903/archive/2008/06/25/2584675.aspx
uElapse
[in] Specifies the time-out value, in milliseconds.
Windows NT/2000/XP: If uElapse is greater than USER_TIMER_MAXIMUM, the timeout is set to 1.Windows 2000/XP: If uElapse is less than USER_TIMER_MINIMUM, the timeout is set to USER_TIMER_MINIMUM.Windows Server 2003: If uElapse is greater than USER_TIMER_MAXIMUM, the timeout is set to USER_TIMER_MAXIMUM.Windows XP SP2/Windows Server 2003 SP1: If uElapse is less than USER_TIMER_MINIMUM, the timeout is set to USER_TIMER_MINIMUM. If uElapse is greater than USER_TIMER_MAXIMUM, the timeout is set to USER_TIMER_MAXIMUM.此外,SetTimer定时也是很不准的。如果要求较高的精度,可以用CreateWaitableTimer、SetWaitableTimer函数。
使用了sleep,会有线程的切换,即使Sleep(1),加上线程切换时间,也就相当于Sleep(15)左右,所以参数小于这个数的时候,不管用哪个,基本没有太大的差别
楼主在网上找找关于精确定时的文章就明白了
SetTimer好像只能到五十几个毫秒吧
不建议用Waitable Timer ,他是异步调用回调函数,更是不精确.