WAIT

WAIT [ Delay ]

递归调用事件循环。

如果指定 Delay

则直到过了 Delay 指定的秒数后函数才返回。

Delay 是一个浮点数值. 因此, 如果你想等待 100 ms, 则如下:
Wait 0.1

如果 Delay 是0:

函数处理所有挂起的事件并立即返回,而不忽略任何事件。

在 Gambas 3.18前, WAIT 0 等同于 WAIT 0.001.

如果没有指定 Delay

函数处理所有待处理事件,并立即返回。在这种特殊情况下,会忽略(键盘和鼠标)输入事件。

这种特定效果仅发生在GUI组件中。

WAIT NEXT

自从 3.15

WAIT NEXT

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

如果从事件处理程序中调用 WAIT ,可能会发生无限递归并引起堆栈溢出。

例如下面的代码:

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.

在这种情况下,可以换用SLEEP语句来解决问题。

参见