D
dorble
Unregistered / Unconfirmed
GUEST, unregistred user!
在一个程序需要大量使用延时,开始用sleep然后发现程序运行时挂起状态,然后用这个procedure Delay(msecs:integer);<br>var <br> Tick: DWord;<br> Event: THandle;<br>begin<br> Event := CreateEvent(nil, False, False, nil);<br> try<br> Tick := GetTickCount + DWord(msecs);<br> while (msecs > 0) and (MsgWaitForMultipleObjects(1, Event, False, msecs, QS_ALLINPUT) <> WAIT_TIMEOUT) do<br> begin<br> Application.ProcessMessages;<br> msecs := Tick - GetTickcount;<br> end;<br> finally<br> CloseHandle(Event);<br> end;<br>end;<br><br>也有问题感觉还不如sleep<br>有人给我下面这个函数procedure Delay(msecs: integer);<br>var<br> FirstTickCount: Longint;<br>begin<br> FirstTickCount := GetTickCount;<br> repeat<br> Application.ProcessMessages();<br> sleep(1);<br> until ((GetTickCount - FirstTickCount) >= Longint(msecs));<br>end;<br>为什么里面有一句sleep(1)那不是也用了sleep这个函数吗?<br>谁告诉到底那个函数好用?