WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: jkjk12 on September 16, 2015, 10:08:29 AM

Title: WinWaitExist
Post by: jkjk12 on September 16, 2015, 10:08:29 AM
How do I use a WHILE statement to wait for a window to exist?

RunHide("\\server\share\ProgramToRun.exe","")
While WinWaitExist == (@FALSE, 2)
EndWhile
Message("OK", "Now we see the window")


OR

RunHide("\\server\share\ProgramToRun.exe","")
While WinWaitExist == @FALSE (~Alaris, 3)
EndWhile
Message("OK", "Now we see the window")

Both fail.

Thank you. 
Title: Re: WinWaitExist
Post by: td on September 16, 2015, 11:19:06 AM
I would hope they both failed.  There are numerous ways to use WinWaitExist in a while loop.   It depends on your intentions.  But first you may want to review your the function's syntax in the Consolidated WIL Help file.  You may not need to use it in a loop.

Here is a simple example of using the function in a loop:
Code (winbatch) Select

Run("Notepad.exe", "")

while 1
   if WinWaitExist("~Notepad", 1) then break
   Pause("Notepad", "Still waiting")
endwhile


Title: Re: WinWaitExist
Post by: snowsnowsnow on September 17, 2015, 03:38:02 AM
Note, incidentally, that if you do just want to wait "forever" (which is the effect of the WHILE loop), then you can just pass -1 as the "how long to wait" parameter, like this:

; No WHILE loop at all
WinWaitExist("winnamegoeshere",-1)
Pause("It is","there!")
Title: Re: WinWaitExist
Post by: td on September 17, 2015, 07:36:03 AM
At the risk of splitting a hair or two unnecessarily, a while loop obviously does not necessarily cause waiting forever. For example, pressing the 'Cancel' button on the Pause function's message display in the above loop would cause loop exit without the application window being found. 
Title: Re: WinWaitExist
Post by: snowsnowsnow on September 17, 2015, 07:39:11 AM
Quote from: td on September 17, 2015, 07:36:03 AM
At the risk of splitting a hair or two unnecessarily, a while loop obviously does not necessarily cause waiting forever. For example, pressing the 'Cancel' button on the Pause function's message display in the above loop would cause loop exit without the application window being found.

I was actually addressing the OP.  And in his loop, there was no Pause() statement.

Clearly, when you added in the Pause() statement, then it was no longer a simple "Wait forever until the window appears" loop.

One might also infer that in the OP's actual application, there was some reason for coding it as a WHILE loop - that in the actual program, the loop is not empty.
Title: Re: WinWaitExist
Post by: td on September 17, 2015, 08:14:55 AM
Given the nature of the original post in this topic, a qualifying explanation seemed appropriate to avoid misunderstanding.   And, yes, the -1 option should have been explicitly mentioned in the first reply. 
Title: Re: WinWaitExist
Post by: DAG_P6 on October 19, 2015, 10:16:25 PM
From time to time, I have coded similar wait loops into scripts. I always put a Yield statement in the loop, to relinquish the processor so that other message pumps get a chance to process their messages.