Sign in to follow this  
Followers 0
Noob

Can a function have a 'time-out' time?

7 posts in this topic

I'd like (if possible) to tell a function to end after 20 seconds in case it doesn't complete what it was set to do for what ever reason.

Is this at all possible?

Share this post


Link to post
Share on other sites



I'd like (if possible) to tell a function to end after 20 seconds in case it doesn't complete what it was set to do for what ever reason.

Is this at all possible?

Sure... when you program it that way .. look at the Timer???() functions... ;)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks. That gives me hope ;) I looked at the time functions, but I had no clue how to do it. I'll look again now that I know it's doable.

Share this post


Link to post
Share on other sites

I feel like doing somthing nice right now :evil:

It's not tested, but you get the picture if you havent seen the ;) by now :lmao:

Func mytest()
    Local $begin = TimerInit()
    Do
        If TimerDiff($begin) > 20000 Then ExitLoop
        $c += 1
        Sleep(0)
    Until $c  < -1
EndFunc

Share this post


Link to post
Share on other sites

I tried using Timer() functions in an infinite loop before; it maxes out the CPU.

-Cool-

Share this post


Link to post
Share on other sites

I tried using Timer() functions in an infinite loop before; it maxes out the CPU.

-Cool-

No it does not. The code you have in the loop does.

That's why the sleep is there. Calling sleep wit 0 volunterly gives up the rest of your current cpu time slot (not entierly true in AutoIt as it is in the control of the runtime engine).

Yes, you will still consume a lot of CPU but your playing nice with the rest of the system. Use sleep(100) if you want to prevent ~100% CPU usage.

Share this post


Link to post
Share on other sites

I feel like doing somthing nice right now :evil:

It's not tested, but you get the picture if you havent seen the ;) by now :lmao:

Func mytest()
    Local $begin = TimerInit()
    Do
        If TimerDiff($begin) > 20000 Then ExitLoop
        $c += 1
        Sleep(0)
    Until $c  < -1
EndFunc

Uten, this Noob is very grateful that you were in the mood for doing a good deed ;-)

It seems like this is exactly what I need! Thanks again!

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