解决了 CPU 耗用 100% 问题的延时函数

字体大小: 中小 标准 ->行高大小: 标准
在主程序中延时,网上广为流传的是 GetTickCount();加  application.processmessages;
的空循环,这样去来的效果会是延时期间 CPU 耗用率为 100% ,而如果用 Sleep 会全世界都死掉.

只改了一句, CPU 耗用问题下来了![:D]

procedure Delay(msec:integer);
//延时函数,msec 为微秒(千分之1秒)
var
FirstTickCount : real;
begin
 FirstTickCount := GetTickCount();
 FirstTickCount := FirstTickCount + msec;

 While FirstTickCount >  GetTickCount() do
   Application.HandleMessage; //关键在这里

end;

delay (5000); // 延时 5 秒 

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/67930.html