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

c#, timer

Solution

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.

Problem

I've used a Windows multimedia dll to created a high resolution timer with timSetEvent() But the `timeSetEvent()` page recommends the use of: CreateTimerQueueTimer() How can I use CreateTimerQueueTimer() to execute a method every 10 milliseconds in C#?

Original source