forever Posted September 3, 2004 Share Posted September 3, 2004 (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 WendsecondHotKeySet("^!{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) WEndhelp plz! Edited September 3, 2004 by forever Link to comment Share on other sites More sharing options...
this-is-me Posted September 3, 2004 Share Posted September 3, 2004 Remove While 1 Wend and While (1) Wend or else replace with While 1 Sleep(100) Wend Who else would I be? Link to comment Share on other sites More sharing options...
forever Posted September 3, 2004 Author Share Posted September 3, 2004 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..?? Link to comment Share on other sites More sharing options...
sugi Posted September 3, 2004 Share Posted September 3, 2004 (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 September 3, 2004 by sugi Link to comment Share on other sites More sharing options...
forever Posted September 3, 2004 Author Share Posted September 3, 2004 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 More sharing options...
sugi Posted September 3, 2004 Share Posted September 3, 2004 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 More sharing options...
Administrators Jon Posted September 3, 2004 Administrators Share Posted September 3, 2004 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. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
Administrators Jon Posted September 3, 2004 Administrators Share Posted September 3, 2004 How about a function called RandomFunc() that executes any one of the AutoIt functions randomly. I like it. Adding to the todo list. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
SlimShady Posted September 3, 2004 Share Posted September 3, 2004 (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 September 3, 2004 by SlimShady Link to comment Share on other sites More sharing options...
Administrators Jon Posted September 3, 2004 Administrators Share Posted September 3, 2004 I will stop adding to this thread as it would be cruel and enjoyable. Lar. Mwhuahahaa. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
redndahead Posted September 4, 2004 Share Posted September 4, 2004 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. 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 Postred Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now