由于某种原因,我的计时器不会一直倒计时,它有时会回到前一秒左右。
例如:如果我在49秒开始计时,这打印出来了:
(以毫秒为单位)
48774
47374个
48909 //不一致
47063
46212个
44987个
48426 //不一致
46294 //不一致
44738
43636个
42410个
......等等
我所做的全部传递两个整数(分钟和秒)并将它们组合在一起得到总的毫秒数。
这是我的代码:
on run {input, parameters}
tell application "iTerm"
activate
if (count of windows) = 0 then
set t to (create window with default profile)
else
set t to current window
end if
tell t
tell current session
write text ("vim \"" & POSIX path of first item of input as text) & "\""
end tell
end tell
end tell
end run
如何获得一致显示的毫秒数?
编辑:
我也尝试将此添加到onTick但它仍无法正常工作
new CountDownTimer(((min * 60 + sec) * 1000), 1000) {//total time, interval
public void onTick(long millisUntilFinished) {
System.out.println(millisUntilFinished);
//...
}
}
答案 0 :(得分:3)
我发现onTick()是从前一个onTick()运行的时间开始计算的,这会在每个tick上产生一个小错误。
请参阅此帖子:android CountDownTimer - additional milliseconds delay between ticks
答案 1 :(得分:0)
即使您在API中指定毫秒级的值,默认情况下系统计时器的分辨率大约为+/- 15ms(因操作系统等而异)。
可以更改,请参见此处:https://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/