Noob Posted November 26, 2006 Share Posted November 26, 2006 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? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 26, 2006 Developers Share Posted November 26, 2006 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 More sharing options...
Noob Posted November 26, 2006 Author Share Posted November 26, 2006 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. Link to comment Share on other sites More sharing options...
Uten Posted November 27, 2006 Share Posted November 27, 2006 I feel like doing somthing nice right now It's not tested, but you get the picture if you havent seen the by now Func mytest() Local $begin = TimerInit() Do If TimerDiff($begin) > 20000 Then ExitLoop $c += 1 Sleep(0) Until $c < -1 EndFunc Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Cool1Net6 Posted November 27, 2006 Share Posted November 27, 2006 I tried using Timer() functions in an infinite loop before; it maxes out the CPU. -Cool- Link to comment Share on other sites More sharing options...
Uten Posted November 27, 2006 Share Posted November 27, 2006 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. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Noob Posted November 27, 2006 Author Share Posted November 27, 2006 I feel like doing somthing nice right now It's not tested, but you get the picture if you havent seen the by now 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now