Timer

From Real Software Documentation

Jump to: navigation, search

     

For web applications, see WebTimer.
Class (inherits from Object)

A Timer is an object that can execute code after a specified period of time or at a repeated interval. If added to a window via the Window Layout Editor, it is not visible in the built application since it is not a control.

Because it is subclassed from Object rather than RectControl, you can instantiate it via code with the New operator.

Constants
ModeMultiple ModeOff ModeSingle


Events
Action


Properties
Enabled Left Period
Index Mode Top


Methods
Reset


Notes

Although the Timer appears in the list of Built-in controls in the Window Layout Editor, this is done only as a convenience to programmers. In terms of the object hierarchy, the Timer is not a control. It is subclassed from Object. This means you can create Timers in your code via the New operator, just as with other objects.

The Mode property controls the interval used to execute the Timer's Action event handler. If the Mode is not 0 (ModeOff), the Timer waits for the Period to pass before executing the Action event handler. If the Mode is set to ModeOff at Runtime, the Timer will immediately cease waiting and the Action event handler will no longer be executed.

The Timer will continue to execute its Action event handler (assuming the Mode property is not set to ModeOff) regardless of whether the window is frontmost or not. The visibility of the window also has no impact on the execution of a Timer's Action event handler. The Timer has been designed so that it yields time to other applications running on the computer so as not to bog down the machine.

Updating the User Interface using a Timer

An important use of a Timer is to update the interface with the results from some computation or some other time-intensive operation. This calculation or lengthly operation is done via Thread, but the Thread itself does not update the interface. Instead, the Timer periodically checks the status of the other operation and then updates the interface as necessary. The Timer itself is running in the main thread. An example project is in the Thread class section.

Examples

A Timer can be used to monitor keydown events. The following code in the Action event of a Timer detects whether the Up, Down, Left, or Right arrow keys are pressed.

If Keyboard.AsyncKeyDown(123) then
StaticText1.text="left arrow key"
end if
If Keyboard.AsyncKeyDown(124) then
StaticText1.text="right arrow key"
end if
If Keyboard.AsyncKeyDown(125) then
StaticText1.text="down arrow key"
end if
If Keyboard.AsyncKeyDown(126) then
StaticText1.text="Up arrow key"
end if

See Also

Object, Thread, WebTimer classes.

Personal tools