Sign in to follow this  
Followers 0
XLimas

Loops eating my CPU

5 posts in this topic

Hello mates,

Since I'm just a newbie, I'd like to ask you how to make infinite loop which doesn't use that much of CPU.

I tried different loops in my small experience and all of them took my CPU to work at around 40-50%.

Posted Image

Even function WinWait() uses my CPU same way.

Here is shortened script i use:

HotKeySet("{`}", "Startit")
HotKeySet("{End}", "Finish")

Do
    Sleep(100)
Until False

Func Startit()
    MouseClick("left")
    Send("^{c}")
    Send("!{TAB}")
    Send("^{v}")
EndFunc

Func Finish()
    Exit 0
EndFunc

Do anyone know how i can get rid out of it?

Is there any other way to make loops that doesn't use that much of CPU?

Thanks in advance!

Share this post


Link to post
Share on other sites



XLimas, I had the same issue in a script I built a while back. I think your sleep may be too short. I put in a sleep of 1 second (1000), and my CPU usage went from 50% to 0 - 1%. You may give that a shot.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

?? that is strange, for me this script...

HotKeySet("{`}", "Startit")
HotKeySet("{End}", "Finish")

Do
    Sleep(1)
Until False

Func Startit()
    MouseClick("left")
    Send("^c")
    Send("!{TAB}")
    Send("^v")
EndFunc

Func Finish()
    Exit
EndFunc

gives me this CPU usage.

Posted Image

If i dont put any sleep the CPU usage is about 40% or 50%

Are you shure that process is the one from that script, maybe is a remaining script test.

EDITED: Also i correct something from your script. v and c are not special characters so dont have any {}

Edited by monoscout999

Share this post


Link to post
Share on other sites

Hmmm, maybe i wrote a bad example...

Try this one:

HotKeySet("{`}", "Startit")
HotKeySet("{End}", "Finish")
$var=0

Do
    If $var=1 Then
        ;Repeats some tasks
        Send("a")
    EndIf
Until False

Func Startit()
    If $var=0 Then
        $var=1
    Else
        $var=0
    EndIf
EndFunc

Func Finish()
    Exit 0
EndFunc

Maybe i use wrong syntax or i do something wrong?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hmmm, maybe i wrote a bad example...

Try this one:

HotKeySet("{`}", "Startit")
HotKeySet("{End}", "Finish")
$var=0

Do
    If $var=1 Then
        ;Repeats some tasks
        Send("a")
    EndIf
Until False

Func Startit()
    If $var=0 Then
        $var=1
    Else
        $var=0
    EndIf
EndFunc

Func Finish()
    Exit 0
EndFunc

Maybe i use wrong syntax or i do something wrong?

You need to put a sleep in the loop. with that script you get for shure an CPU usage above 40% Edited by monoscout999

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  
Followers 0