Sign in to follow this  
Followers 0
Blastblood

My script uses so much CPU Please help me!!

6 posts in this topic

#1 ·  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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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