Jump to content

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


Noob
 Share

Recommended Posts

  • Developers

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... ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
Link to comment
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.

Link to comment
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!

Link to comment
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
 Share

  • Recently Browsing   0 members

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