Jump to content

Will Script use more resources than needed?


Recommended Posts

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

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 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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Indeed I now see the murky way in which I described my intentions. Thanks for setting me straight!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...