Jump to content

My script uses so much CPU Please help me!!


Recommended Posts

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

Ok i solve the problem with this

$timer = TimerInit ()
While 1
    $nMsg = GUIGetMsg ();i dont know what are these codes for but it works =D
    Switch $nMsg
        Case - 3
            Exit
    EndSwitch
    If TimerDiff($timer) >= 5000 Then;5 Seconds
        $timer = TimerInit()
        MsgBox(0,"asd","asdasd")
    EndIf
WEnd
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

  • Developers

Just for the record: You use GUIGetMsg() when you want to "read" the messages from your GUI,.

In this case just simply put a Sleep(10) in the While...Wend loop.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...