Werty Posted August 17, 2011 Posted August 17, 2011 (edited) I'm getting a constant 8-12% cpu load using this while loop, despite the Sleep()... While 1 $msg = GUIGetMsg() Switch $msg Case -3 On_Exit() Case Else For $loop = 0 To 37 If $msg = $morphvalue[$loop] Then _GUICtrlSlider_SetPos($morphhandle[$loop], GUICtrlRead($morphvalue[$loop])) ControlSend("","",$morphhandle[$loop],"{UP}") EndIf Next EndSwitch $msg = "" Sleep(10) WEnd It's an array of sliders in my GUI that controls sliders in another program. It works as it should, but I'm getting cpu load eventhough I have the sleep() in there, removing the sleep() hogs the cpu even more obviously. Edited August 18, 2011 by Werty Some guy's script + some other guy's script = my script!
PsaltyDS Posted August 18, 2011 Posted August 18, 2011 The Sleep() isn't required in the While/WEnd because GuiGetMsg() automatically imposes a delay when called in a loop. Your For/Next loop should only run if a $msg was received. Once the For/Next loop finds a match, it should exit. While 1 $msg = GUIGetMsg() If $msg Then Switch $msg Case -3 On_Exit() Case Else For $loop = 0 To 37 If $msg = $morphvalue[$loop] Then _GUICtrlSlider_SetPos($morphhandle[$loop], GUICtrlRead($morphvalue[$loop])) ControlSend("", "", $morphhandle[$loop], "{UP}") ExitLoop EndIf Next EndSwitch EndIf WEnd Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
JohnOne Posted August 18, 2011 Posted August 18, 2011 I think its probably not that high if its a single core processor. You could try adding a sleep to your For Next loop because thats what is doing the work. A sleep is already added internally with GUIGetMsg() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Werty Posted August 18, 2011 Author Posted August 18, 2011 The Sleep() isn't required in the While/WEnd because GuiGetMsg() automatically imposes a delay when called in a loop. Your For/Next loop should only run if a $msg was received. Once the For/Next loop finds a match, it should exit. While 1 $msg = GUIGetMsg() If $msg Then Switch $msg Case -3 On_Exit() Case Else For $loop = 0 To 37 If $msg = $morphvalue[$loop] Then _GUICtrlSlider_SetPos($morphhandle[$loop], GUICtrlRead($morphvalue[$loop])) ControlSend("", "", $morphhandle[$loop], "{UP}") ExitLoop EndIf Next EndSwitch EndIf WEnd Thanks, that did it, back at 0% idle I think its probably not that high if its a single core processor. Quadcore, so it was eating away half a core :/ Some guy's script + some other guy's script = my script!
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