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