Sign in to follow this  
Followers 0
pageone

Help With Cpu Usage Script

4 posts in this topic

Hi

I am just learning Autoit and have come across a problem

This is a CPU usage script from Autoit and i have added a progress bar and made it so that it runs continuously.

However once it is running it cannot be closed or any other fuction initiated...... Help please ..

Can i have the cpu being continuiously monitored and run other functions.. eventually i want to integrate this into other programs and still be able to run them :think:

#include <GUIConstants.au3>


; == GUI generated with Koda ==);
$Form1 = GUICreate("AForm1", 289, 168, 316, 253)
GUISetState(@SW_SHOW)
$refresh =""
$USAGE = GUICtrlCreateLabel($refresh,15,15,50,20)
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0);removes XP standard Theme
;Dim $LABEL = GuiCtrlCreateLabel ("CPU:", 30, 16, 70, 15)
Dim $PROGRESS3 = GuiCtrlCreateProgress (30, 50, 100, 8)
GUIctrlSetBkColor($PROGRESS3,0x000000)
GUICtrlSetColor(-1,0xff0000)

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

While 1
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Processor", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
            
            
    If IsObj($colItems) Then
        For $objItem In $colItems
            $Refresh  = GUICtrlSetData($USAGE,$objItem.LoadPercentage & " %")
        $refresh = GUICtrlSetData ($progress3, $objItem.LoadPercentage )
        Next
    Else
        MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_Processor")
    EndIf
WEnd


While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;;;;;
    EndSelect
WEnd

Share this post


Link to post
Share on other sites



AutoIt doesn't have an actual MultiThread option, so you'll want to take a look at neogia's alternative: http://www.autoitscript.com/forum/index.php?showtopic=23545


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

AutoIt doesn't have an actual MultiThread option, so you'll want to take a look at neogia's alternative: http://www.autoitscript.com/forum/index.php?showtopic=23545

Here is an example of what SmOke_N is talking about, requires Coroutine.au3 v1.0.3 from my signature.

#include "Coroutine.au3"

HotKeySet("{ESC}", "_Exit")

$WatchCPU = _CoCreate('Func _WatchCPU()|    $Form1 = GUICreate("CPU Usage", 160, 100, 200, 253)|    GUISetState(@SW_SHOW)|  $USAGE = GUICtrlCreateLabel("0%",15,15,50,20)|  DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0);removes XP standard Theme|    Dim $PROGRESS3 = GuiCtrlCreateProgress (30, 50, 100, 8)|    GUIctrlSetBkColor($PROGRESS3,0x000000)| GUICtrlSetColor(-1,0xff0000)|   $wbemFlagReturnImmediately = 0x10|  $wbemFlagForwardOnly = 0x20|    $colItems = ""| $strComputer = "localhost"| $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")|  While 1|If GUIGetMsg() == -3 Then Exit|     $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Processor", "WQL", _|                    $wbemFlagReturnImmediately + $wbemFlagForwardOnly)|     If IsObj($colItems) Then|           For $objItem In $colItems|              GUICtrlSetData($USAGE,$objItem.LoadPercentage & " %")|              GUICtrlSetData ($progress3, $objItem.LoadPercentage )|          Next|       Else|           MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_Processor")|        EndIf|  WEnd|EndFunc')

_CoStart($WatchCPU)
$donePerformingFunctions = 0

While 1
; Perform other functions here in this loop
    If $donePerformingFunctions Then
        _Exit(); You don't have to exit the loop like this, but be sure you call _Exit() or _CoCleanup() when you're done
    EndIf
    Sleep(100)
WEnd

Func _Exit()
    _CoCleanup()
    Exit
EndFunc
Edited by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

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