QueryPerformanceFrequency 做定时??
public void delay(long delay_Time){
long stop_Value = 0;
long start_Value = 0;
long freq = 0;
long n = 0;
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
QueryPerformanceFrequency(ref freq); //获取CPU频率
long count = delay_Time * freq / 1000000; //us级
QueryPerformanceCounter(ref start_Value); //获取初始前值
while (n < count) //不能精确判定
{
QueryPerformanceCounter(ref stop_Value);//获取终止变量值
n = stop_Value - start_Value;
}
}
.
.
.
delay(150);
本来是想定的150us,结果得出实际时间差不多250左右,而且还很不稳定。不知道什么原因!
希望大大能解惑下!