Microsoft Knowledge Base |
|
How to Wait a Finite Time for a Run Process to Terminate |
|
|
Last reviewed: September 7, 1995
Article ID: Q136203 |
|
The information in this article applies to:
SUMMARYThe Run TestBasic statement starts an application and either returns immediately or waits for the application to exit. The Run statement has an optional second parameter that specifies when it is to return to the TestBasic script to allow it to continue processing. If the second parameter is not specified, the Run statement won't return until the application is closed. Specifying NoWait as the second parameter makes the Run statement return immediately, which causes the application to run asynchronously with the TestBasic script. Waiting for an application to complete is often useful while testing applications. However, if the application being waited upon cannot complete for unknown reasons, the Run statement will never return, so the the TestBasic script will never continue. By uing the Win32 API function WaitForSingleObject in conjunction with CreateProcess, you can specify a finite time to wait. This article shows by example how to do this.
MORE INFORMATIONWaitForSingleObject returns when the specified object is in the signaled state or when the time-out interval elapses. An application object becomes signaled when it terminates. WaitForSingleObject needs a handle to the application, which can be obtained from the CreateProcess function. CreateProcess is a Win32 API function that starts an application running and returns a handle to that application. It is used in this article as a replacement for the TestBasic Run statement.
Step-by-Step Example for Using WaitForSingleObject and CreateProcessThe following steps detail the process for creating a TestBasic script that will:
NOTE: This sample code uses five Win32 API functions: CloseHandle, CreateProcess, GetExitCodeProcess, TerminateProcess, and WaitForSingleObject. For more information concerning these functions, please see the Win32 SDK Help file.
|
|
Additional reference words: 4.00 Win32
©1997 Microsoft Corporation. All rights reserved. Legal Notices. |