Mohamed Mansour's Personal Website
Portfolio
HIGH RESOLUTION TIMER
Posted in DOTNET with 468 views.
The Classic Windows Forms Timer in .NET 2.0 is a bit slow, one may want to use the highest resolution timer the system has. This library will use the fastest Windows Timer by interoping the Kernel32.dll inorder to access the QueryPerfomanceCounter.
The QueryPerformanceCounter function returns the current value of the high-resolution performance counter. The current Windows Forms Timer, returns a 1 second resolution, in many cases that may be enough. When timing is a must, using the QueryPerformanceFrequency is the best in its class.
The only thing you do is import the library included in the zip file to your references. The sourcecode is given since the only way I learned programming was from all the opensource out there. So the least I could do is contribute as well.
Comparisons between existing timers
Function Units Resolution --------------------------------------------------------------------------- Now, Time, Timer seconds 1 second GetTickCount milliseconds approx. 10 ms TimeGetTime milliseconds approx. 10 ms QueryPerformanceCounter QueryPerformanceFrequency same
The table above shows the difference in resolution within the current Timing methods available in .NET 2.0. It is clear that QueryPerformanceCounter is the best for crucial timing applications.
Download
The Library: here
The Source Code: here
References