|
Script Object |
|
See Also: |
The Script.Wait() method waits until nMilliseconds elapses or Script.StopWait() is called.
VBScript:
JScript:
| Script | The Script object. |
| nMilliseconds | Optional. The number of milliseconds to wait. Use apgWaitInfinite to wait until Script.StopWait() is called. |
Script.Wait() can be used to pause a script, but it is also used to pause the script so event handlers for out-of-process COM objects can be called. Event notification from out-of-process COM objects is asynchronous, so a mechanism like Script.Wait() must be used for events to be received. In-process COM objects send events while an object method is being executed, so Script.Wait() should not be used for in-process objects.
Event handlers can use the Script.Waiting property to determine if the script is in a Script.Wait() statement. Event handlers can also use the Script.StopWait() statement to stop the wait after the event handler returns.
If a user closes the status dialog for a script, Script.StopWait() is implicitly called. This gives you an easy way to run a script until a user explicitly ends it.
This example uses the "InternetExplorer.Application" object, which is part of IE4 and IE5. Since this object is an out-of-process COM object, Script.Wait() is used to let the script receive events. This is a "surfer recorder" script: All pages that are viewed using the instantiated browser are written to a text file. When the browser is closed, StopWait() is called, which ends the Wait() and lets the script exit.
<%# @LANGUAGE=Javascript #%>
<%#
// ------------------------------------------------------------------------
// ie_evnts.apg
//
// Reports all browsed HTML docs, in order
// ------------------------------------------------------------------------
function IE_DocumentComplete(objIE, sURL)
{
var dateNow = new Date();
Output.Write(dateNow + ": " + sURL + " - " + objIE.LocationName + "\r\n");
}
function IE_OnQuit()
{
Script.DisconnectEvents(oIE);
if (Script.Waiting)
// Let the script exit
Script.StopWait();
}
// Global Internet Explorer object
var oIE;
function Main()
{
Output.Filename = "pagelist.txt";
Output.Append = true;
// Load IE
oIE = Script.CreateObject("InternetExplorer.Application", "IE_");
oIE.Visible = true;
// Navigate to a page
oIE.Navigate("http://www.yahoo.com");
// Wait until Script.StopWait() is called
// This occurs when IE is shut down.
Script.Wait();
// Write an end-of-file marker
Output.Write("-------------------------------\r\n");
}
#%>