Sign in to follow this  
Followers 0
forever

Abnormal CPU Usage?

11 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Remove

While 1

Wend

and

While (1)

Wend

or else replace with

While 1

Sleep(100)

Wend


Who else would I be?

Share this post


Link to post
Share on other sites

Remove

While 1

Wend

and

While (1)

Wend

or else replace with

While 1

Sleep(100)

Wend

<{POST_SNAPBACK}>

when i remove then wouldn't that close the script? after it run once..??

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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" ?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

How about a function called RandomFunc() that executes any one of the AutoIt functions randomly.

<{POST_SNAPBACK}>

Wouldn't that scr*w up your PC?

y'know with FileDelete, RegDelete, INIDelete

Edited by SlimShady

Share this post


Link to post
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

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