dufran3 Posted March 28, 2011 Share Posted March 28, 2011 I have this teeny tiny script that waits for a specific window to appear, and then closes that window when it does. Is my loop running and using too many resources? ;Close print window TraySetIcon('printer.ico') While 1 WinWait('Status not Available') WinClose('Status not Available') WEnd Link to comment Share on other sites More sharing options...
Bowmore Posted March 28, 2011 Share Posted March 28, 2011 (edited) As it is unlikely that this window will pop up frequently and probably not critical that it is closed instantly, i would add a 2 second sleep. It would also be better to use WinExists instead of WinWait. The result will be the same but it will use less CPU. It will also give you the option of adding additional pop up widows that need to be closed. ;Close print window TraySetIcon('printer.ico') While 1 Sleep(2000) If WinExists('Status not Available') Then WinClose('Status not Available') EndIf WEnd Edit: Added last sentence Edited March 28, 2011 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 28, 2011 Moderators Share Posted March 28, 2011 dufran3,Why the loop? WinWait does the waiting on its own - and it idles the CPU automatically too. ;Close print window TraySetIcon('printer.ico') WinWait('Status not Available') ; This stays active until the window is detected WinClose('Status not Available')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...
dufran3 Posted March 28, 2011 Author Share Posted March 28, 2011 dufran3, Why the loop? WinWait does the waiting on its own - and it idles the CPU automatically too. ;Close print window TraySetIcon('printer.ico') WinWait('Status not Available') ; This stays active until the window is detected WinClose('Status not Available') M23 Because I don't want to have to start the script every time I need it. The way you adjusted it, the script ends after it closes the window. Once the script closes the window, I want it to then wait again for the window to appear, etc. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 28, 2011 Moderators Share Posted March 28, 2011 dufran3, Perhaps you should have made that clearer at the beginning. In that case I see nothing wrong with your script as originally posted. 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...
dufran3 Posted March 28, 2011 Author Share Posted March 28, 2011 dufran3,Perhaps you should have made that clearer at the beginning. In that case I see nothing wrong with your script as originally posted. M23Indeed I now see the murky way in which I described my intentions. Thanks for setting me straight! 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