Jump to content

Recommended Posts

Posted

Near the beginning of my app, I have

$startTime = TimerInit()

Then I test it in a loop, taking action if it runs too long, then don't bother with it again.

Is there:

(1) a way to turn it off? (I'm not using #include <Timers.au3>, just the built-in functions.)

or

(2) any performance hit having an unneeded timer accumulating time for the rest of the time the app runs?

Thanks!

Posted (edited)

Stop? TimerDiff "stop" it, show the difference and if you call TimerInit() again it start from 0

Don't understand how you use it in a loop, you use Do...Until or what?

$sec = "3000"
$timer = TimerInit()
Do
; Your Func
Until TimerDiff($timer) >= $sec
Edited by johnmcloud
Posted

  On 2/25/2013 at 3:08 PM, 'johnmcloud said:

Stop? TimerDiff "stop" it

Are you sure?

Example()

Func Example()
    Local Const $hTimer = TimerInit()
    Local $iDiff = 0, $iDiffPrevious = 0
    While 1
        $iDiff = Round(TimerDiff($hTimer))
        If Not ($iDiff = $iDiffPrevious) Then
            $iDiffPrevious = $iDiff
            ConsoleWrite($iDiff & @CRLF)
        EndIf
        If TimerDiff($hTimer) > 2000 Then ExitLoop
    WEnd
EndFunc   ;==>Example

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • Moderators
Posted

VelvetElvis,

TimerInit uses no resources other than the variable in which you store the returned value. it is not a timer as such, it just returns a numerical timestamp which you can then use with TimerDiff to determine an elapsed time. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

  On 2/25/2013 at 3:08 PM, 'johnmcloud said:

Don't understand how you use it in a loop, you use Do...Until or what?

While 1
$target = _ImageSearch(@ScriptDir & "\Clips\test.gif", 1, $x1, $y1, 0); Testing only
If $target = 1 Then ExitLoop

; Timeout if Java hasn't loaded HOD in 30 seconds
If TimerDiff($startTime) > 30000 Then
     MsgBox(8208, $appname, "Timed out waiting for HOSTS icons to load." & @CRLF & "Please logon manually.")
     Exit
EndIf
Sleep(500)
WEnd

I could've used TimerDiff() instead of the "While 1" too. It's just in the initial stages.

Posted

  On 2/25/2013 at 3:44 PM, 'Melba23 said:

VelvetElvis,

TimerInit uses no resources other than the variable in which you store the returned value. it is not a timer as such, it just returns a numerical timestamp which you can then use with TimerDiff to determine an elapsed time. :)

M23

Thanks M23. That's what I needed.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...