Sign in to follow this  
Followers 0
bittware

How to design a time limited loop?

2 posts in this topic

Hello experts,

I want to monitor one input variable state change within defined time interval, say 5 seconds. If timeout, just jump out of monitor loop. During monitor phase, we can still do something else. How to implement that? Thanks.

BRs,

bittware

Share this post


Link to post
Share on other sites



How to design a time limited loop?

$TimeOut = 5000 ;timeout in ms
$timer = TimerInit()
Do
    ;some code
    ;don't forget a short sleep
Until TimerDiff($timer) > $TimeOut

I want to monitor one input variable state change within defined time interval, say 5 seconds.

I think you're looking for AdlibRegister()

During monitor phase, we can still do something else.

AutoIt is not multithreaded, so you can't do two things at the same time. You can however make sure you have no functions that take a long time to execute, so other functions get a chance to execute in between.

This means you want to find alternatives to slow loops inside functions. Example: Instead of a functions with a 5 seconds timeout, use a 250 ms timeout and call it 20 times.

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