Why is minimum Threading.Timer interval 15ms despite timeBeginPeriod(1)

前端 未结 1 629
無奈伤痛
無奈伤痛 2021-01-14 12:34

The following snippet

    [DllImport(\"winmm.dll\", EntryPoint = \"timeBeginPeriod\")]
    public static extern uint TimeBeginPeriod(uint uMilliseconds);

           


        
相关标签:
1条回答
  • 2021-01-14 13:02

    The comment is wrong. My experience has been that the multimedia timer does not affect the .NET timers. That is, it doesn't change their minimum supported time period, which appears to be about 15 ms. It might improve their accuracy. That is, if you ask for 16 ms, you might actually get 16 ms and not "somewhere between 15 and 30 ms."

    Why the .NET timers are limited to 15 ms is not clear to me.

    There's some information about it in the accepted answer here.

    If you're looking for a higher resolution timer for .NET, you probably shouldn't use the multimedia timers. Those have been deprecated in the Windows API. Use the Timer Queue Timers. See my articles:

    • .NET Timer Resolution
    • Exploring options for better timers
    • Using the Windows Timer Queue API

    Another option is to use the Waitable Timer. Full source for that is available at http://www.mischel.com/pubs/waitabletimer.zip

    0 讨论(0)
提交回复
热议问题