Get program control if user is inactive
Execute some code after a given number of seconds, when the user does not interact with the program.
When to use the ON IDLE trigger?
If an interactive instruction has the control, the program waits for a user interaction like an action or field input. If the end user leaves the workstation, or switches to another application, the program cannot get the control and is frozen until the user comes back. You might want to execute some code, after a period of inactivity, for example to refresh the displayed data by doing a new database query, or even after a long period, to terminate the program automatically.
Implementing the ON IDLE trigger
ON IDLE trigger in the
dialog. This trigger is dialog specific, it is typically defined in the main dialog of the program,
but it can also be defined in every dialog.- Consider using the
ON IDLEonly in dialogs that do not handle field input, such asDISPLAY ARRAYandMENU. If used in input dialogs, this trigger may execute while the current field contains an incomplete value. The trigger will produce field value validation and raise an input error. However,ON IDLEcan be used in input dialogs where the user cannot enter invalid values (for example when usingCHECKBOX,RADIOGROUP,COMBOBOX, and character-type fields likeTEXTEDIT). - When implementing multiple or parallel
dialogs with
DIALOGblock, do not mix severalON IDLEclauses in different sub-dialog blocks: specify a uniqueON IDLEclause at theDIALOGblock level. - Obviously, it does not make much sense to mix
ON TIMERandON IDLEclauses.
DEFINE seconds SMALLINT
LET seconds = 120
DISPLAY ARRAY ...
...
ON IDLE seconds
MESSAGE "Automatic data refresh..."
-- Reload the array with a new database result set
...Note that the parameter of the ON IDLE trigger can be an integer variable, but
it will only be read when the dialog is started. Changing the variable during dialog execution will
have no effect.
A value of zero or less than zero disables the timeout trigger.