pageone Posted April 25, 2006 Share Posted April 25, 2006 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 expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 25, 2006 Moderators Share Posted April 25, 2006 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 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. Link to comment Share on other sites More sharing options...
Onoitsu2 Posted April 25, 2006 Share Posted April 25, 2006 also I think you might benifit from the use of an adlib function, with a very low delay. Things I have made:[font="Trebuchet Ms"]_CheckTimeBlock UDF(LT)MOH Call Ignore List (MOH = Modem On Hold)[/font] Link to comment Share on other sites More sharing options...
neogia Posted April 25, 2006 Share Posted April 25, 2006 (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=23545Here 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 April 25, 2006 by neogia [u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia 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