Host Timing Considerations
When you customize a viewer, your code must accommodate potential host processing delays for wait-dependent operations. For such operations, your code must detect when the host finishes processing and is ready to receive more commands. Sending additional input before the host is ready will result in an error.
To allow you to reliably program for wait-dependent operations, the Viewer API includes a variety of wait-related methods. Although all of these methods enable you to determine when the host is ready for input, each addresses a specific timing-sensitive situation.
Depending on the host processing situation, some wait methods are better than others to determine when the host is ready for input. Below is a description of the Viewer API wait methods.
- waitForCursorWaits for the host cursor to move to a specified location. This is useful for applications that change the cursor location from screen to screen; however, it is useful only if you know what the cursor location will be.
- waitForStringWaits until a specified string appears on the screen. Although this is usually the most reliable method of waiting, it is practical only in cases where you are sure of the sequence of screens.
- waitHostQuietWaits until there has been no activity in the host session for a specified amount of time, referred to as the settle time. The lower the settle time, the faster your application will run. The higher the settle time, the less chance there is for your application to send input before the host is ready. A workable settle time depends on the typical response time of your host application and network speed. Typically, one to two seconds works.