Skip to content

Latest commit

 

History

History
15 lines (12 loc) · 1.25 KB

README.md

File metadata and controls

15 lines (12 loc) · 1.25 KB

HighPrecisionTimer

A high precision timer in .NET

There are often times where people would like regularly spaced events at a resolution greater than C# and Windows can normally provide (~15ms). This is a limitation of the standard timer mechanisms built into the Windows OS. There do exist high precision timing APIs for multimedia applications, but these are not exposed via .NET APIs. For applications that need timer event precision on the order of 1ms, these APIs are useful. This library is a quick example of using the Multimedia Timer API.

I will note that this API changes system wide settings that can degrade system performance (esp battery life), so buyer beware. Since Windows is not a real-time OS, the load on your system may cause the MM timer be delayed resulting in gaps of 100 ms that contain 100 events in quick succession, rather than 100 events spaced 1 ms apart. Some additional reading on MM timers.

I originally posted the code as an answer to a question on Stack Overflow