Function SetTimerEvent() Foundation

Starts a timer thread which executes a code block at the defined time interval

Syntax
SetTimerEvent( [<nNewInterval>], ;
               [<bNewBlock>]   )  --> { nOldInterval, bOldBlock }
Parameters
<nInterval>
<nInterval> is a numeric value indicating the time interval in 1/100 seconds at which the code block <bBlock> is executed. If the value zero is passed, the code block is no longer executed.
<bBlock>
<bBlock> is a code block automatically executed in a separate thread at specific time intervals.
Return

The return value of SetTimerEvent() is an array of two elements. The first element contains the time interval and the second element contains the code block previously defined for the timer event. When no code block was previously defined, both elements contain the value NIL.

Description

The function SetTimerEvent() starts a thread independent of the running program in which the code block <bBlock> is evaluated at a consistent time interval. In this separate thread, other components of the program can be executed but they must be self contained and independent of the main program. A common example for the timer thread is the display of the time (see example). But more complex program components, like print jobs, can be set to run without the main program being disturbed.

Output on the screen from the timer thread should not be performed with QOut(), DispOut() or DevOut() without first saving the cursor position and then restoring it. Otherwise, the cursor position changes in the main program. When screen output must occur in the timer thread, it is preferable to use the function DispOutAt() which does not change the cursor position.

Examples
SetTimerEvent()
// In the example, the time is displayed once per second. 
// The timer thread continues running even though the main 
// program is receiving input from the user using READ. 

PROCEDURE Main 
   LOCAL cVar1:= "Xbase++" , cVar2:="for 32bit" 
   CLS 

   SetTimerEvent(100, {|| DispOutAt(0, 0, Time()) } ) 

   @ 10, 0 Say "Variable1" GET cVar1 
   @ 12, 0 Say "Variable2" GET cVar2 
   READ 

   SetTimerEvent(0) 

RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.