A_TickCount is inaccurate after leaving the computer off for a few hours

Get help with using AutoHotkey and its commands and hotkeys
asdsk9skdsdas
Posts: 36
Joined: 10 Mar 2019, 21:52

A_TickCount is inaccurate after leaving the computer off for a few hours

Post by asdsk9skdsdas » 24 Dec 2020, 02:04

I have a script that I have scheduled with Task Scheduler to run at log in/system start; however, I have noticed that the if condition I have set with A_TickCount always fails if I run the script after my computer has been shutdown for a few hours. When the script fails, if I restart my computer, it works, so it is clearly caused by A_TickCount being inaccurate after shutting down for a few hours. Example script:

Code: Select all

#NoEnv
SetWorkingDir %A_ScriptDir%
SetWinDelay, 1
#NoTrayIcon

if (A_TickCount < 300000) 
{
	MsgBox, Test
}
Edit:
QueryPerformanceCounter() value at boot
Image

A_TickCount value at boot
Image

The values are confirmed to not start from 0 at boot after a few hours of shutting down.
Last edited by asdsk9skdsdas on 24 Dec 2020, 17:53, edited 1 time in total.

just me
Posts: 7717
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: A_TickCount is inaccurate after leaving the computer off for a few hours

Post by just me » 24 Dec 2020, 06:05

A_TickCount cannot be inaccurate because it always contains what GetTickCount() returns.

User avatar
JoeWinograd
Posts: 1648
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: A_TickCount is inaccurate after leaving the computer off for a few hours

Post by JoeWinograd » 24 Dec 2020, 11:54

asdsk9skdsdas wrote:A_TickCount being inaccurate after shutting down for a few hours
Check out my article:
How to solve the problem of incorrect System Uptime being reported when a system has been up for a long time

Scroll down to the paragraph that begins with this:
As a final comment on the issue of determining system uptime, it has been documented that TickCount functions can be inaccurate in Windows 10 because of the Fast Startup feature, which is enabled by default in W10. You may disable it (when logged in as an admin) as follows:
Maybe that's the reason in your case. Regards, Joe

just me
Posts: 7717
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: A_TickCount is inaccurate after leaving the computer off for a few hours

Post by just me » 25 Dec 2020, 12:03

JoeWinograd wrote:... it has been documented that TickCount functions can be inaccurate in Windows 10 because of the Fast Startup feature ...
They aren't inaccurate. The system remains in a suspended state and won't be shut down.

User avatar
JoeWinograd
Posts: 1648
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: A_TickCount is inaccurate after leaving the computer off for a few hours

Post by JoeWinograd » 25 Dec 2020, 13:31

just me wrote:They aren't inaccurate.
OK, I see your point, but it depends on your definition of "inaccurate", imo. I'm fine with calling it "inaccurate" in this situation, along with the accompanying comment on Fast Startup. Pretty much semantics, imo...not worth a diatribe. Regards, Joe

Post Reply

Return to “Ask For Help”