Condividi tramite


Visual Basic Concepts

Handling Requests Pending to an ActiveX Component

It usually takes only a fraction of a second to set a property or call a method of an object. At times, however, your request may not be finished immediately.

  • If you call the Close method of a Workbook in Microsoft Excel while the user has a dialog box open, Microsoft Excel signals that it is busy and cannot execute your request. This can lead to a component busy condition*.*

  • If you call a method that performs a lengthy operation, such as a large amount of database work when the database is very active, you may try to perform another operation while the first operation is still pending. This can lead to a request pending condition*.*

  • If you have two or more programs making calls to a shared component, one call must be completed before another can begin. Components handle such conflicts by serializing the requests, that is, making them wait in line. This can also lead to a request pending condition.

Component busy is like getting a busy signal when you make a telephone call. You know you're not going to get through, so you may as well hang up and try again later.

Request pending is like having your call go through, and then having the person you're calling keep you talking much longer than you intended. If your request is serialized, then request pending is like having the other party pick up the telephone and say immediately, "Can you hold, please?"

The Component Busy Condition

A component may reject your request because it has a modal dialog box open, or because a user edit operation is in progress. For example, Microsoft Excel rejects requests from a client application while a spreadsheet cell is being edited.

Visual Basic assumes that the busy condition is temporary and keeps trying the request for a specified timeout interval. When that time is up, Visual Basic displays the Component Busy dialog box, as shown in Figure 10.6.

Figure 10.6   The Component Busy dialog box

The user can retry the request, cancel the request, or switch to the component and fix the problem (for example, by dismissing the dialog box). If the user chooses Cancel, the error &h80010001 (RPC_E_CALL_REJECTED) is raised in the procedure that made the request.

The Request Pending Condition

Once a component has accepted your application's request, your application must wait until the request has been completed. If the request takes a long time, the user may attempt to minimize your program or resize it to get it out of the way.

After a short timeout interval, Visual Basic responds to such attempts by displaying the Component Request Pending dialog.

The appearance of the Component Request Pending dialog box is slightly different from the Component Busy dialog. The Cancel button is disabled, as shown in Figure 10.7, because the request in progress cannot be canceled.

Figure 10.7   The Component Request Pending dialog box

Switching to the component is useful only if it has halted to display an error message as a result of your request. This should not be a common occurrence, because the proper behavior for a component is to return an error condition to the program that called it.

For More Information   For more information, see "Changing the Component Busy or Request Pending Messages," "Controlling Timeout Intervals," and "Raising an Error on Component Busy Timeout" later in this chapter.