本文介绍了如何在Inno Setup中获得时差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个超时如下的while循环...如何在Inno Setup中编写此循环?

I want to write a while loop with a timeout like follows... How to write this in Inno Setup?

InitialTime = SystemCurrentTime ();

Timeout = 2000; //(ms)

while (!condition) {
    if (SystemCurrentTime () - InitialTime > Timeout) {
    // Timed out
       break;
    }
}

谢谢!

推荐答案

要使其在Inno Setup中变得简单,可以使用 GetTickCount 调用.

To make it simple in Inno Setup, you can use GetTickCount calls.

因此,它不会精确地在2000毫秒(或您想要的任何值)上超时,但会足够接近可接受的时间.

So, it will not timeout exactly at 2000 milliseconds (or whatever value you want) but close enough to be acceptable.

您必须意识到的其他限制是:

Other limitation you must be aware of is:

在代码中,它显示如下:

In code, it shows like this:

[Code]
function GetTickCount: DWord; external 'GetTickCount@kernel32 stdcall';

procedure WaitForTheCondition;
const
  TimeOut = 2000;
var
  InitialTime, CurrentTime: DWord;
begin
  InitialTime := GetTickCount;
  while not Condition do
  begin
    CurrentTime := GetTickCount;
    if    ((CurrentTime - InitialTime) >= TimeOut) { timed out OR }
       or (CurrentTime < InitialTime) then { the rare case of the installer running  }
                                           { exactly as the counter overflows, }
      Break;
  end;
end;

上面的功能并不完美,在极少数情况下在计数器溢出(机器每49.7天连续运行一次)的那一刻正在运行,因为它会立即超时当发生溢出时(可能在所需的等待之前).

The above function is not perfect, in the rare case of that being running at the moment the counter overflows (once each 49.7 days of the machine is continuously running), because it will timeout as soon as the overflow occurs (maybe before the desired wait).

这篇关于如何在Inno Setup中获得时差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 04:17
查看更多