Blastblood Posted May 13, 2010 Share Posted May 13, 2010 (edited) My script is using so much CPU #include <Timers.au3> $starttime = _Timer_Init();starts timer while(1) if _Timer_Diff($starttime)>3000 Then MsgBox(0,"asdas","high time!"); show a message in every 5 secs "i was to use it for calling a func but it uses so much cpu" $starttime = _Timer_Init() ; to reset the timer EndIf WEnd i have a func which include while wend codes in my main script but i dont want the func to fulfill lines every time. But in every 3 sec. I write a script like this, it works but uses so much CPU (about 50%). I can't use sleep instead of timer method because i have a GUI window and edit fields during sleep they become inactive etc etc Please suggest me some new methods to run a fucn every xx time or a method to reduce the usage of CPU. Sorry for the bad english by the way Note: is there any code like "local sleep()" which only sleeps the func not the whole script Edited May 13, 2010 by Blastblood Link to comment Share on other sites More sharing options...
l3ill Posted May 13, 2010 Share Posted May 13, 2010 Read up on the GUIGetMsg function under the Message Loop Mode in the help file. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Blastblood Posted May 13, 2010 Author Share Posted May 13, 2010 Ok i solve the problem with this $timer = TimerInit () While 1 $nMsg = GUIGetMsg ();i dont know what are these codes for but it works =D Switch $nMsg Case - 3 Exit EndSwitch If TimerDiff($timer) >= 5000 Then;5 Seconds $timer = TimerInit() MsgBox(0,"asd","asdasd") EndIf WEnd Link to comment Share on other sites More sharing options...
l3ill Posted May 13, 2010 Share Posted May 13, 2010 GUI Reference - MessageLoop Mode$nMsg = GUIGetMsg ();i dont know what are these codes for but it works =DBasic MessageLoop Format The general layout of MessageLoop code is: While 1 $msg = GUIGetMsg() ... ... WEnd Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Blastblood Posted May 13, 2010 Author Share Posted May 13, 2010 GUI Reference - MessageLoop ModeBasic MessageLoop Format The general layout of MessageLoop code is: While 1 $msg = GUIGetMsg() ... ... WEnd Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive. Thanks for your advise Link to comment Share on other sites More sharing options...
Developers Jos Posted May 13, 2010 Developers Share Posted May 13, 2010 Just for the record: You use GUIGetMsg() when you want to "read" the messages from your GUI,. In this case just simply put a Sleep(10) in the While...Wend loop. Jos 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...
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