Sign in to follow this  
Followers 0
posixcompliant

Non-blocking Sleep or suitable equivalent implementation?

4 posts in this topic

I'm looking to fire off several actions at certain, precise and staggered offsets from an initial point in time. So let's say that after precisely 17 seconds, the first function is fired. After 19 seconds, the second function is fired. After 21 seconds, the third function is fired. The problem is that each of these three staggered functions may block for a brief but indeterminate period of time, and I'm looking to delay each function relative to the starting time, as opposed to delaying each function relative to the completion of the preceding one. Is this kind of thing possible in AutoIt?

Share this post


Link to post
Share on other sites



Oh! I actually seem to have come to a solution to my problem via TimerInit() and TimerDiff(). Thanks!

Share this post


Link to post
Share on other sites

AdlibRegister() also could help.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

you could use my >simple stopwatch udf.

here a possible way of use:

Stopwatch(3) ; reset counter to 0 and start counting

    ; call here your first function()
    ; if your function takes longer than 3 seconds to complete
    ; then it will delay the entire process of course

Do ; example of use do/until loop to wait

Until Stopwatch() >= 3000 ; stay here for 3 seconds (3000 ms) from previous stopwatch reset

ConsoleWrite(Stopwatch() & " ms elapsed" & @CRLF)

; ----------------------------------------------------

Stopwatch(3) ; reset counter to 0 and start counting

    ; call here your second function()
    ; if your function takes longer than 4 seconds to complete
    ; then it will delay the entire process of course

While Stopwatch() <= 4000; stay here for 4 seconds (4000 ms) from previous stopwatch reset

WEnd ; example of use while/Wend loop to wait

ConsoleWrite(Stopwatch() & " ms elapsed" & @CRLF)



; #FUNCTION# (snippet) ==========================================================================================================
; Name...........: Stopwatch
; Description ...: returns the number of milliseconds counted (according to actions requests by caller)
; Syntax.........: Stopwatch([$action])
; Parameters ....: $action: 0 - pause counting
;                           1 - resume counting
;                           2 - reset counter to 0 and stops
;                           3 - reset counter to 0 and start counting
;                           4 - (default) just ruturns actual counting value and status (status in @extended)
;
; Return values .: number of milliseconds in counter
;                  @extended contains paused status (1 or 0)
;                  1 if stopwatch is in pause
;                  0 if stopwatch is counting
;
; Author ........:
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: yes
; ===============================================================================================================================

Func Stopwatch($ToggleTo = 4)
    Static Local $Paused = True
    Static Local $Stopwatch = 0
    Static Local $TotalTime = 0
    Switch $ToggleTo
        Case 0 ; pause counter
            If $Paused Then
                SetExtended($Paused) ; $Paused status
                Return $TotalTime ; already paused, just return current $TotalTime
            Else
                $TotalTime += TimerDiff($Stopwatch)
                $Paused = True
                SetExtended($Paused)
                Return $TotalTime
            EndIf
        Case 1 ; unpause counter
            If $Paused Then
                $Stopwatch = TimerInit()
                $Paused = False
                SetExtended($Paused)
                Return $TotalTime
            Else
                SetExtended($Paused)
                Return $TotalTime + TimerDiff($Stopwatch)
            EndIf
        Case 2 ; reset to 0 and pause
            $Paused = True
            $TotalTime = 0
            SetExtended($Paused)
            Return $TotalTime
        Case 3 ; reset to 0 and restart
            $Paused = False
            $TotalTime = 0
            $Stopwatch = TimerInit()
            SetExtended($Paused)
            Return $TotalTime
        Case 4 ; return status
            SetExtended($Paused)
            If $Paused Then
                Return $TotalTime
            Else
                Return $TotalTime + TimerDiff($Stopwatch)
            EndIf
    EndSwitch
EndFunc   ;==>Stopwatch

EDIT:

moved the calling of your function outside the loops in listing

EDIT2:

after reading better the first post, I see that there is not need to use my stopwatch in this case, but the use of TimerInit() / TimerDiff() is sufficient.
anyway... it also works

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0