Jump to content

Abnormal CPU Usage?


forever
 Share

Recommended Posts

Ive made 2 au3 scripts which got abnormal cpu usage (over 60-70%), could anyone help?

first

#Include "GUIConstants.au3"


Opt ('GUITaskbarEntry', 0)
Opt("TrayIconHide", 1) 
Opt ("GUICoordMode", 1)
Opt ("GUINotifyMode", 1)
$style = $WS_POPUP
GUICreate("Desktop Background", 1181, 687, 0, 257, $style)


$PIC_1 = GUISetControl("pic", "E:\graphic/samurizedesign/bgs/01.jpg", 0, 0, 640, 480)


GUIShow()


While 1
Wend

second

HotKeySet("^!{PgUp}", "lockdown")
HotKeySet("^!{PgDn}", "openGui")
$lockdown = "0"

Func lockdown()
$PID = ProcessExists("explorer.exe")
If $PID Then 
MsgBox("","","locking down")
Run("lockdown.exe")
EndIf
EndFunc

Func openGui()
$PID = ProcessExists("gui.exe")
If $PID = 0 Then 
Run("gui.exe")
EndIf
EndFunc


While (1)
WEnd

help plz!:ph34r:

Edited by forever
Link to comment
Share on other sites

Remember one thing when you're writing a script: A computer is not intelligent. It will do exactly as you tell it do, not how you want it to do. Also the computer does not care how stupid this is or how many errors there are in what you told it to do.

Think about that you're telling AutoIt to do when you're writing

While 1
WEnd

You're telling AutoIt to start a loop (While 1). And as soon as AutoIt has entered the loop it's told to start the loop again (WEnd). As soon as the second run of the loop has started, it's again told to restart the loop. and restart again and again and again...

Of course AutoIt tries to do this as fast as possible and eats up your CPU.

What you forgot, is to tell AutoIt to sleep a short time in every loop so it does not do 100 000 loops in one second but maybe only 4 loops a second.

So just add a Sleep(250) or something like that.

Edited by sugi
Link to comment
Share on other sites

Remember one thing when you're writing a script: A computer is not intelligent. It will do exactly as you tell it do, not how you want it to do. Also the computer does not care how stupid this is or how many errors there are in what you told it to do.

Think about that you're telling AutoIt to do when you're writing

While 1
WEnd

You're telling AutoIt to start a loop (While 1). And as soon as AutoIt has entered the loop it's told to start the loop again (WEnd). As soon as the second run of the loop has started, it's again told to restart the loop. and restart again and again and again...

Of course AutoIt tries to do this as fast as possible and eats up your CPU.

What you forgot, is to tell AutoIt to sleep a short time in every loop so it does not do 100 000 loops in one second but maybe only 4 loops a second.

So just add a Sleep(250) or something like that.

<{POST_SNAPBACK}>

Ive already added 10sec delay now, but is there no other way? to make a script "permanent" ?
Link to comment
Share on other sites

Ive already added 10sec delay now, but is there no other way? to make a script "permanent" ?

Well, any scripting or programming language I know goes through the source from top to bottom (with a few exceptions but it's still the same principle) and exit when they've reached the bottom.

Now you suggest a command like StayForever()?

What's the benefit of that command? It will not lower CPU usage as AutoIt still has to do some tasks like redrawing the GUI or answering to other requests to AutoIt's window)

I cannot see other benefits from it and if that's the only reason write yourself a small function that contains of a While 1... Sleep ... WEnd.

Link to comment
Share on other sites

  • Administrators

Well, any scripting or programming language I know  goes through the source from top to bottom (with a few exceptions but it's still the same principle) and exit when they've reached the bottom.

Now you suggest a command like StayForever()?

What's the benefit of that command? It will not lower CPU usage as AutoIt still has to do some tasks like redrawing the GUI or answering to other requests to AutoIt's window)

I cannot see other benefits from it and if that's the only reason write yourself a small function that contains of a While 1... Sleep ... WEnd.

Yeah, maybe I should just make Sleep() sleep forever if no parameter is given. Easy enough.
Link to comment
Share on other sites

Ahhh the evil that really goes on here. Funny enough none of these people like the viruses that are out but they sure enjoy screwing the programmers. :ph34r:

Anywho, forever look at the changes I made to this post and you should see how to make it run until closed. Look at the change function. It was taken from someone else but runs good.

Click for Post

red

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...