Jump to content

Recommended Posts

I'm looking for a little help, I'm looking to update the variable $CPUPercent and then update the GUI with the new value.  The problem is every time I call the function at the bottom of the while loop my GUI stops allowing inputs until the sleep timer is over.  Is there any way to do what I'm trying to do?

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#Region Variables
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$ComName = @ComputerName
$objServices = ObjGet("winmgmts:\\" & $ComName)
Dim $CPUPercent
#EndRegion

Func _GetCPUPercent ()
Sleep (10000)
$colItems = $objServices.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
    For $objItem In $colItems
        If Not StringInStr($objItem.Name, "Total") = 0 Then
            ConsoleWrite ($objItem.PercentProcessorTime & $objItem.Name & @CRLF)
            $CPUPercent = $objItem.PercentProcessorTime
        EndIf
    Next
Else
    MsgBox (48, "WMI Error", "WMI Error")
EndIf
EndFunc


;MsgBox (1, "data", $CPUPercent)
$DashboardGUI = GUICreate ("Dashboard", 1000, 750)
$CPUPercentLable = GUICtrlCreateLabel ($CPUPercent, 15, 15, 20, 20)
$Exit = GUICtrlCreateButton("Exit", 500, 700)
GUISetState(@SW_SHOW)
Call("_GetCPUPercent")

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $Exit
            Exit
    EndSwitch
Call("_GetCPUPercent")
If GUICtrlRead ($CPUPercentLable) <> $CPUPercent Then
     GUICtrlSetData($CPUPercentLable, $CPUPercent)
EndIf
WEnd

Share this post


Link to post
Share on other sites
Posted (edited)

Yes, AdlibRegister can run as exclusive to the main loop

#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>

#Region Variables
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$ComName = @ComputerName
$objServices = ObjGet("winmgmts:\\" & $ComName)
Dim $CPUPercent
#EndRegion Variables

$DashboardGUI = GUICreate("Dashboard", 1000, 750)
$CPUPercentLable = GUICtrlCreateLabel($CPUPercent, 15, 15, 20, 20)
$Exit = GUICtrlCreateButton("Exit", 500, 700)
AdlibRegister("_GetCPUPercent", 500)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_RESTORE
            AdlibRegister("_GetCPUPercent", 500)
        Case $gui_event_close
            Exit
        Case $Exit
            Exit
    EndSwitch
WEnd

Func _GetCPUPercent()
    If BitAND(WinGetState($DashboardGUI), $WIN_STATE_MINIMIZED) Then Return AdlibUnRegister("_GetCPUPercent")
    $colItems = $objServices.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If IsObj($colItems) Then
        For $objItem In $colItems
            If Not StringInStr($objItem.Name, "Total") = 0 Then
                ConsoleWrite($objItem.PercentProcessorTime & $objItem.Name & @CRLF)
                $CPUPercent = $objItem.PercentProcessorTime
                If GUICtrlRead($CPUPercentLable) <> $CPUPercent Then
                    GUICtrlSetData($CPUPercentLable, $CPUPercent)
                EndIf
            EndIf
        Next
    Else
        Exit MsgBox(48, "WMI Error", "WMI Error")
    EndIf
EndFunc   ;==>_GetCPUPercent

 

Edited by Deye

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

×
×
  • Create New...