Jump to content

Recommended Posts

Posted (edited)

My script is using so much CPU

#include <Timers.au3>
$starttime = _Timer_Init();starts timer

while(1)
if _Timer_Diff($starttime)>3000 Then 
    MsgBox(0,"asdas","high time!"); show a message in every 5 secs "i was to use it for calling a func but it uses so much cpu"
    $starttime = _Timer_Init() ; to reset the timer
    EndIf
WEnd

i have a func which include while wend codes in my main script but i dont want the func to fulfill lines every time. But in every 3 sec. I write a script like this, it works but uses so much CPU (about 50%). I can't use sleep instead of timer method because i have a GUI window and edit fields during sleep they become inactive etc etc

Please suggest me some new methods to run a fucn every xx time or a method to reduce the usage of CPU.

Sorry for the bad english by the way :idea:

Note: is there any code like "local sleep()" which only sleeps the func not the whole script

Edited by Blastblood
Posted

GUI Reference - MessageLoop Mode

$nMsg = GUIGetMsg ();i dont know what are these codes for but it works =D

Basic MessageLoop Format

The general layout of MessageLoop code is:

While 1
 $msg = GUIGetMsg()
 ...
 ... 
WEnd

Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive.

Posted

GUI Reference - MessageLoop Mode

Basic MessageLoop Format

The general layout of MessageLoop code is:

While 1
 $msg = GUIGetMsg()
 ...
 ... 
WEnd

Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive.

Thanks for your advise :idea:

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
  • Recently Browsing   0 members

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