Mich9874 Posted November 28, 2011 Share Posted November 28, 2011 (edited) Hi guys! I have a loop that calls this function: Func TestColors($checkbox,$DColor) Local $foundcount[4] $foundcount[0] = 0 $foundcount[1] = 0 $foundcount[2] = 0 $foundcount[3] = 0 $size = WinGetPos($checkbox) $areatopleft = PixelSearch($size[0],$size[1],$size[0]+($size[2]/2),$size[1]+($size[3]/2),$DColor,$ColorAccuracy,$SkipPixels) If not @error Then $foundcount[0] = 1 EndIf $areatopright = PixelSearch($size[0]+($size[2]/2),$size[1],$size[0]+$size[2],$size[1]+($size[3]/2),$DColor,$ColorAccuracy,$SkipPixels) If not @error Then $foundcount[1] = 1 EndIf $areabottomleft = PixelSearch($size[0],$size[1]+($size[3]/2),$size[0]+($size[2]/2),$size[1]+$size[3],$DColor,$ColorAccuracy,$SkipPixels) If not @error Then $foundcount[2] = 1 EndIf $areabottomright = PixelSearch($size[0]+($size[2]/2),$size[1]+($size[3]/2),$size[0]+$size[2],$size[1]+$size[3],$DColor,$ColorAccuracy,$SkipPixels) If not @error Then $foundcount[3] = 1 EndIf Return $foundcount EndFunc I pass it a GUI window and a color to search for, it divides the GUI window into 4 segments and returns an array of which segments my color was found in. $ColorAccuracy and $SkipPixels are defined as globals. When I call the function in a loop such as: Local $Quadrants[4] Do $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $Quit = 1 EndSelect $Quadrants = TestColors("MyGUI",$SearchColor) Until $Quit = 1 Exit The GUI slows down to the point that clicking the close button takes multiple seconds (4 to 10) to exit the program. While the GUI is "locked out" the logic continues to run, adding a loop counter shows that it's running multiple loops per second so it's not just waiting for a pixelsearch to complete . I've tried putting sleep()'s in there but it seems to make no difference. I want the pixelsearch to run as often as possible but I don't want it locking up the application like this obviously. The CPU load sits at 3 or 4% while the program is running. Can someone please enlighten me as to what I'm doing wrong? Thanks! Mich Edited November 28, 2011 by Mich9874 Link to comment Share on other sites More sharing options...
Skitty Posted November 28, 2011 Share Posted November 28, 2011 Hi guys! I have a loop that calls this function: Func TestColors($checkbox,$DColor) Local $foundcount[4] $foundcount[0] = 0 $foundcount[1] = 0 $foundcount[2] = 0 $foundcount[3] = 0 $size = WinGetPos($checkbox) $areatopleft = PixelSearch($size[0],$size[1],$size[0]+($size[2]/2),$size[1]+($size[3]/2),$DColor,$ColorAccuracy,$SkipPixels) If not @error Then $foundcount[0] = 1 EndIf $areatopright = PixelSearch($size[0]+($size[2]/2),$size[1],$size[0]+$size[2],$size[1]+($size[3]/2),$DColor,$ColorAccuracy,$SkipPixels) If not @error Then $foundcount[1] = 1 EndIf $areabottomleft = PixelSearch($size[0],$size[1]+($size[3]/2),$size[0]+($size[2]/2),$size[1]+$size[3],$DColor,$ColorAccuracy,$SkipPixels) If not @error Then $foundcount[2] = 1 EndIf $areabottomright = PixelSearch($size[0]+($size[2]/2),$size[1]+($size[3]/2),$size[0]+$size[2],$size[1]+$size[3],$DColor,$ColorAccuracy,$SkipPixels) If not @error Then $foundcount[3] = 1 EndIf Return $foundcount EndFunc I pass it a GUI window and a color to search for, it divides the GUI window into 4 segments and returns an array of which segments my color was found in. $ColorAccuracy and $SkipPixels are defined as globals. When I call the function in a loop such as: Local $Quadrants[4] Do $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $Quit = 1 EndSelect $Quadrants = TestColors("MyGUI",$SearchColor) Until $Quit = 1 Exit The GUI slows down to the point that clicking the close button takes multiple seconds (4 to 10) to exit the program. While the GUI is "locked out" the logic continues to run, adding a loop counter shows that it's running multiple loops per second so it's not just waiting for a pixelsearch to complete . I've tried putting sleep()'s in there but it seems to make no difference. I want the pixelsearch to run as often as possible but I don't want it locking up the application like this obviously. The CPU load sits at 3 or 4% while the program is running. Can someone please enlighten me as to what I'm doing wrong? Thanks! Mich Since autoit isn't multi-thread capable, you get this shit, I would suggest either checking the gui message via adlibregister or create another process for the gui that controls functions in the main process through some nifty form of interprocess communication. But then I didn't look at your code because I'm a noob and don't really know anything about anything related to searching pixel values since I've never needed it and the problem might be there. Link to comment Share on other sites More sharing options...
Mich9874 Posted November 28, 2011 Author Share Posted November 28, 2011 (edited) Since autoit isn't multi-thread capable, you get this shit, I would suggest either checking the gui message via adlibregister or create another process for the gui that controls functions in the main process through some nifty form of interprocess communication.I just tried using adlibregister to make the call to GUIGetMessage() and it doesn't help. It seems that the message isn't being generated by the button click for several seconds after the click is made.Cheers for the suggestion!Mich. Edited November 28, 2011 by Mich9874 Link to comment Share on other sites More sharing options...
Mich9874 Posted November 28, 2011 Author Share Posted November 28, 2011 Further testing shows that hitting the escape key on the keyboard exits the program with no delay! Now I'm utterly confused... Mich. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2011 Moderators Share Posted November 28, 2011 Mich9874,I have just run the code you posted on a 1500x1000 window and I found the average time for your TestColors function was about 20ms. The [X] on the GUI I added to the code reacted instantly the function returned - which at 20ms means virtually instaneously. expandcollapse popup#include <GUIConstantsEx.au3> Global $Quit = 0, $Quadrants[4], $ColorAccuracy = 50, $SkipPixels = 1 #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) GUISetState() ; Confirm the size of the window being checked $size = WinGetPos("[CLASS:SciTEWindow]") ConsoleWrite($size[2] & " - " & $size[3] & @CRLF) Do $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $Quit = 1 EndSelect ; Time the function $iBegin = TimerInit() $Quadrants = TestColors("[CLASS:SciTEWindow]", 0xFDFDFD) ConsoleWrite(TimerDiff($iBegin) & @CRLF) Until $Quit = 1 Exit Func TestColors($checkbox, $DColor) Local $foundcount[4] $foundcount[0] = 0 $foundcount[1] = 0 $foundcount[2] = 0 $foundcount[3] = 0 $size = WinGetPos($checkbox) $areatopleft = PixelSearch($size[0], $size[1], $size[0] + ($size[2] / 2), $size[1] + ($size[3] / 2), $DColor, $ColorAccuracy, $SkipPixels) If Not @error Then $foundcount[0] = 1 EndIf $areatopright = PixelSearch($size[0] + ($size[2] / 2), $size[1], $size[0] + $size[2], $size[1] + ($size[3] / 2), $DColor, $ColorAccuracy, $SkipPixels) If Not @error Then $foundcount[1] = 1 EndIf $areabottomleft = PixelSearch($size[0], $size[1] + ($size[3] / 2), $size[0] + ($size[2] / 2), $size[1] + $size[3], $DColor, $ColorAccuracy, $SkipPixels) If Not @error Then $foundcount[2] = 1 EndIf $areabottomright = PixelSearch($size[0] + ($size[2] / 2), $size[1] + ($size[3] / 2), $size[0] + $size[2], $size[1] + $size[3], $DColor, $ColorAccuracy, $SkipPixels) If Not @error Then $foundcount[3] = 1 EndIf Return $foundcount EndFunc ;==>TestColorsAre you sure you are not running something else in the loop or in the function because at the moment I can see no reason why you get a sluggish response from your GUI? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mich9874 Posted November 28, 2011 Author Share Posted November 28, 2011 (edited) Are you sure you are not running something else in the loop or in the function because at the moment I can see no reason why you get a sluggish response from your GUI? When I run the code you provided (modified to run the TestColors function twice in a row with different variables, which my program does) the delay on clicking x is between 1 second and about 6. It changes every time I test it. If I run the function only once in the loop, it exits fast... Can you see any reason why running the function twice back to back would cause problems?Thanks for helping....Mich. Edited November 28, 2011 by Mich9874 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2011 Moderators Share Posted November 28, 2011 Mich9874, What does the timer return and how big is your scanned area? You see the values in the bottom SciTE window. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
sebgg Posted November 28, 2011 Share Posted November 28, 2011 Ive found this make a huge difference in performance _DwmEnable(False) Func _DwmEnable($WhatToDo) DllCall("dwmapi.dll", "long", "DwmEnableComposition", "uint", $WhatToDo) EndFunc cant remeber who i got it from but thanks to them not me if it helps seb GC - Program to rapidly manipulate DNA SequencesRotaMol - Program to measure Protein Size Link to comment Share on other sites More sharing options...
Mich9874 Posted November 29, 2011 Author Share Posted November 29, 2011 Mich9874,What does the timer return and how big is your scanned area? You see the values in the bottom SciTE window. M23The scanned area is 1733 x 1021 and the timing is ~80 for one function call per loop and ~150 for two. With one function call per loop the program exits reasonably fast, with two it takes a considerably longer time.With the function sebgg suggested (thankyou!!!!) the timing changes to ~8 for one function call and ~14 for two! A ten fold increase in performance! Wow!Mich. 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