Accurate Windows timer? System.Timers.Timer() is limited to 15 msec

前端 未结 6 1544
粉色の甜心
粉色の甜心 2020-12-18 14:42

I need an accurate timer to interface a Windows application to a piece of lab equipment.

I used System.Timers.Timer() to create a timer that ticks every 10 msec, but

6条回答
  •  温柔的废话
    2020-12-18 15:20

    The limitation is given by the systems heartbeat. This typically defaults to 64 beats/s which is 15.625 ms. However there are ways to modify these system wide settings to achieve timer resolutions down to 1 ms or even to 0.5 ms on newer platforms:

    1. Going for 1 ms resolution by means of the multimedia timer interface (timeBeginPeriod()):

      See Obtaining and Setting Timer Resolution.

    2. Going to 0.5 ms resolution by means of NtSetTimerResolution():

      See Inside Windows NT High Resolution Timers.

    You may obtain 0.5 ms resolution by means of the hidden API NtSetTimerResolution().

    I've given all the details in this SO answer.

提交回复
热议问题