Controlling Timeout Intervals

See Also

You can set the timeout intervals that determine when Visual Basic displays the Component Busy and Component Request Pending dialog boxes, using two properties of the App object.

OLEServerBusyTimeout Property

Determines how long Visual Basic will go on retrying your Automation requests before displaying the Component Busy dialog. The default value is 10000 milliseconds (10 seconds).

OLERequestPendingTimeout Property

Determines how long Visual Basic waits before responding to mouse clicks, keypress events, and other events by displaying the Component Request Pending dialog. The default value is 5000 milliseconds (5 seconds).

The following example shows how the timeout values might be adjusted and reset for a call to the StockAnalysis method of a hypothetical BusinessRules object.

Public Sub SetTimeouts(ByVal lngComponentBusy As _
Long, ByVal lngRequestPending As Long)
   App.OLEServerBusyTimeout = lngComponentBusy
   App.OLERequestPendingTimeout = lngRequestPending
End Sub

Public Sub ResetTimeouts()
   App.OLEServerBusyTimeout = 10000

   App.OLERequestPendingTimeout = 5000
End Sub

Private Sub cmdFullAnalysis_Click()
   On Error Goto FullAnalysis_Error
   ' Set very short timeouts. After 2 seconds,
   ' the user will be notified and keypresses or
   ' clicks will display the Component Busy
   ' and Component Request Pending dialogs.
   SetTimeouts 2, 2
   Me.MousePointer = vbHourglass
   gobjBusinessRules.StockAnalysis txtNYSECode.Text, _
   ATYPE_FULL
FullAnalysis_Cleanup:
   Me.MousePointer = vbDefault
   ResetTimeouts
   Exit Sub

FullAnalysis_Error:
   If Err.Number = &h80010001 Then
      MsgBox "Analysis cancelled"
   Else
      ' Code to handle other errors...
   End If
   Resume FullAnalysis_Cleanup
End Sub

You can set either of these timeouts to very large values, because they are stored as Longs. For example, 86,400,000 milliseconds is a day, which is equivalent to an infinite timeout. When you do this, however, you risk having your program lock up until the component is no longer busy, or until a pending request has completed.

Important   Because these timeout values are properties of the App object, they also affect documents you link or embed using the OLE container control or the Toolbox. If you are using linked or embedded documents and you change these properties for an Automation request, it is a good idea to reset the values afterward.