WAIT

WAIT [ Delay ]

Call the event loop recursively.

If Delay is specified:

The function does not return until Delay seconds elapse.

Delay is a floating point number. So, if you want to wait 100 ms, just do:
Wait 0.1

If Delay is zero:

The function processes all pending events and returns immediately, without ignoring any event.

Before Gambas 3.18, WAIT 0 was an equivalent of WAIT 0.001.

If Delay is not specified:

The function processes all pending events and returns immediately, but in that specific case, input events (keyboard and mouse) are ignored.

This specific effect only occurs with GUI components.

WAIT NEXT

Sinds 3.15

WAIT NEXT

Call the event loop recursively, and waits until at least one event is processed.

Examples

' Waits a little, letting the user interacts with the GUI.
Wait 0.05

' Waits, but the user can just watch what happens...
Wait

' Wait until at least one event is processed.
Wait Next

If you call WAIT from an event handler, you may create infinite recursions, and then stack overflows.

For example, look at the following code:

PUBLIC SUB MySerialPort_Read()

  DIM sData, sTemp AS String
  DIM iTries AS Integer

  FOR iTries = 1 TO 5
    ' wait a bit and read response.
    WAIT 0.01
    ' see if we got some data.
    READ #LAST, sTemp, Lof(LAST)
    sData &= sTemp
    ...
 NEXT

END

WAIT is called without reading anything on the serial port. So it is yet ready for being read, and the Read event is raised recursively again and again until the stack is full.

In that case, you can solve the problem by using the SLEEP instruction instead.

See also