[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceCounter(ref long PerformanceCount);
long qwTicksPerSec; // Number of ticks per second. Based on your computer, only set this once
long qwTime;
// If bUsingQPF returns false, you cant use these - youll have to use timeGetTime.
// I think its for Win98 or Win95 and earlier (cant remember which versions dont support them)
bool bUsingQPF = QueryPerformanceFrequency(ref qwTicksPerSec);
QueryPerformanceCounter(ref qwTime);
// Use QueryPerformanceCounter to get the current time. Subtract
// from previous calls to get the difference.
// Use qwTicksPerSec to get how many ticks per second you have.