Jump to content
Sign in to follow this  
Werty

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

Recommended Posts

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

Some guy's script + some other guy's script = my script!

Share this post


Link to post
Share on other sites

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

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

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

Some guy's script + some other guy's script = my script!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...