[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 can't use these - you'll have to use timeGetTime.
// I think it's for Win98 or Win95 and earlier (can't remember which versions don't 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.