JLanning Posted April 19, 2019 Share Posted April 19, 2019 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? expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Deye Posted April 19, 2019 Share Posted April 19, 2019 (edited) Yes, AdlibRegister can run as exclusive to the main loop expandcollapse popup#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 April 19, 2019 by Deye Link to comment Share on other sites More sharing options...
JLanning Posted April 22, 2019 Author Share Posted April 22, 2019 Thanks so much!!! I was working forever trying to get this done. Link to comment Share on other sites More sharing options...
Deye Posted April 22, 2019 Share Posted April 22, 2019 you're welcome Link to comment Share on other sites More sharing options...
Zedna Posted April 24, 2019 Share Posted April 24, 2019 Also look at this Wiki page: https://www.autoitscript.com/wiki/Interrupting_a_running_function Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now