How can I use CreateTimerQueueTimer to create a high resolution timer in C#?

后端 未结 3 1915
青春惊慌失措
青春惊慌失措 2021-01-18 05:54

I\'ve used a Windows multimedia dll to created a high resolution timer with

timSetEvent()

But the timeSetEvent() page recommends the use

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 06:15

    Here is a link to a C# wrapper for CreateTimerQueueTimer:

    http://social.msdn.microsoft.com/Forums/en-CA/csharpgeneral/thread/822aed2d-dca0-4a8e-8130-20fab69557d2

    (scroll down to the last post by Hobz for the sample class)

    I just tried this out myself and it works fine. One thing you'll need to add, though, is a call to timeBeginPeriod(1) before starting the timer in order to set your system to high-resolution. timeSetEvent calls timeBeginPeriod internally, which is why some people mistakenly assume that it creates a higher-resolution timer.

提交回复
热议问题