Jump to content
Sign in to follow this  
Werty

Trouble with While/case, controls in an array (sliders)

Recommended Posts

Werty

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.

:mellow:

Edited by Werty

Share this post


Link to post
Share on other sites
PsaltyDS

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

:mellow:


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

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
Werty

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

:mellow:

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 :/

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.