Get program control if user inactivity

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 perio 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

To detect user inactivity during a dialog, define an 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.
Important: Consider using the ON IDLE interaction block in dialogs that do not handle field input, such as DISPLAY ARRAY and MENU: In input dialogs, this trigger might be executed when in the middle of a field input, and could force field value validation and raise an input error.
For example:
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 a 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 of less of zero disables the timeout trigger.