我正在创建一个需要运行的过程,然后等待10分钟才能继续运行。
procedure firstTimeRun(const document: IHTMLDocument2);
var
fieldValue : string;
StartTime : Dword;
begin
StartTime := GetTickCount();
WebFormSetFieldValue(document, 0, 'Username', '*******');
WebFormSetFieldValue(document, 0, 'Password', '*******');
WebFormSubmit(document, 0);
if (GetTickCount() >= StartTime+ 600000) then
begin
SecondRun();
end;
end; 我遇到的问题是,当我到达if语句时,它将检查它是否为真,然后继续如何使它保持不变,直到语句为真?
发布于 2013-12-13 16:18:42
天真地回答是,您需要一个while循环:
while GetTickCount() < StartTime+600000 then
;
SecondRun();或者更容易读到,一个repeat循环:
repeat
until GetTickCount() >= StartTime+600000;
SecondRun();但这样做是错误的。你会启动处理器10分钟,却一无所获。我要说明的是,如果您的系统已经运行了49天,那么您将进入GetTickCount封装,然后测试的逻辑就会有缺陷。
操作系统有一个功能来解决您的问题,它被称为Sleep。
Sleep(600000);这会将调用线程阻塞指定的毫秒数。因为线程是块,所以线程在等待时不会占用CPU资源。
这将使调用线程没有响应能力,因此它通常是在后台线程中执行的,而不是应用程序的主线程。
https://stackoverflow.com/questions/20570992
复制相似问题