如何在Inno Setup中获得时差? [英] How to get time difference in Inno Setup?

查看:66
本文介绍了如何在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中变得简单,可以使用

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

GetTickCount函数的分辨率仅限于系统计时器的分辨率,通常在10毫秒到16毫秒之间.

The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds.

因此,它不会精确地在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:

经过的时间存储为DWORD值.因此,如果系统连续运行49.7天,时间将归零.

The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days.

在代码中,它显示如下:

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中获得时差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆