High precision delay

Oct 4 2007 8:43 PM

Hi,

     I had written a app 3 years ago with lots of timing it was running on a PIII and all was working fine, but due to a hardware failure I had change the PC for a Intel dual core and now I have a big problem.  My timing delay is now 3 time slower on the dual code the Thread.Sleep function is many time slower than before.  If I remove the Thread.Sleep the loop suck all my CPU time. Did you have any idee?

Thanks

Sylvain Bissonnette

private void Delay(long TimeOut)

{

long hrRes=0, hrT1=0, hrT2=0, dif=0;

timeBeginPeriod(1);

QueryPerformanceFrequency(ref hrRes);

QueryPerformanceCounter(ref hrT1);

while(dif < TimeOut)

{

QueryPerformanceCounter(ref hrT2);

dif = ((hrT2 - hrT1) * 10000) / hrRes;

if (dif > 10) Thread.Sleep(1);

else Thread.Sleep(0);

}

timeEndPeriod(1);

}