Sign in to follow this  
Followers 0
KAX

timer functions

8 posts in this topic

Hi AutoIt fans!

I would like to use a timer service to get awaked when timer has expired.

But it should work without polling. Means using sleep and waiting in loops.

Has someone got a good idea ?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$Timer_Expiration_Time = 10000 ;10 seconds.
$Timer = TimerInit()

Do
    Sleep(500)
Until TimerDiff($Timer) >= $Timer_Expiration_Time

MsgBox(0, "Time Expired", "It has been " & $Timer_Expiration_Time / 1000 & " seconds.")

Edited by Zib

Share this post


Link to post
Share on other sites

This is not the 'optimal' solution I'm loolking for. Because it doesn't allow you easily to add more timers.

My favorite structure looks like:

...
$timer1 = CreateTimer()
StartTimer($timer1, 1000)  ;starts timer1, time in ms
while $performMainLoop ; main loop

    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE
            Exit

                Case $msg[0] = $TIMEREXPIRED
                        ; check which timer
                        ; perform appr. action
                         StartTimer($timer1, 500); restart it
                ....
    EndSelect
Wend

Share this post


Link to post
Share on other sites

$Timer1_Expiration_Time = 10000 ;10 seconds.
$Timer2_Expiration_Time = 8000 ;8 seconds.
$Timer3_Expiration_Time = 30000 ;30 seconds.

$Timer1 = TimerInit()
$Timer2 = TimerInit()
$Timer3 = TimerInit()

While 1
    Select
        Case TimerDiff($Timer1) >= $Timer1_Expiration_Time
            ;Do something...
            
            $Timer1_Expiration_Time = 5000
            $Timer1 = TimerInit()
            
        Case TimerDiff($Timer2) >= $Timer2_Expiration_Time
            ;Do something else..
        
        Case TimerDiff($Timer3) >= $Timer3_Expiration_Time
            ;Do something else..
            
    EndSelect
WEnd

Something like this? Maybe I am not understanding correctly.

Share this post


Link to post
Share on other sites

...

Something like this? Maybe I am not understanding correctly.

Thanks Zib,

this solution consumes the CPU-power inside the loop, because it polls the used timers at every loop step. I prefer a solution ala WM_TIMER. Which winds up the timers and then only waits for messages. (Hope the waiting for messages does not steal the CPU from all the concurrent running processes!)

Share this post


Link to post
Share on other sites

This is not the 'optimal' solution I'm loolking for. Because it doesn't allow you easily to add more timers.

My favorite structure looks like:

This is what you want: http://www.autoitscript.com/forum/index.ph...st&p=143556

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

unsolved questions to timer functions

The timer function:

DLLCall("user32.dll","int_ptr","SetTimer","hwnd",$gui,"int_ptr",$nID,"int",2000,"ptr",0)

generate repeated timeouts. So good so far. But it seems, that the timers haven't designed to be operated in start-stop mode. (To restart a timer only when a certain event has occured). An other point is to change the timeout.

Can someone help?

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