Class

Xojo.Core.Timer


Warning

This item was deprecated in version 2020r2. Please use Timer as a replacement.

Description

Provides a way to run code at specified intervals.

Properties

Name

Type

Read-Only

Shared

Mode

Modes

Period

Integer

Tolerance

Integer

Methods

Name

Parameters

Returns

Shared

CallNoParams

CallWithArg

argument As Variant

Events

Name

Parameters

Returns

Action

Enumerations

Xojo.Core.Timer.Modes

Modes

Specifies when the timer gets called. (Off, Single, Multiple)

Enum

Description

Off

Disables the Timer. The action event handler is no longer called. This is the default.

Single

Calls the Action event handler once after the Period is reached, then turns the Timer to Off.

Multiple

Call the Action event handler each time the Period is reached.

Property descriptions


Xojo.Core.Timer.Mode

Mode As Modes

Specifies if the timer calls the Action event handler once, multiple times or not at all using the Modes enumeration. The default is Xojo.Core.Timer.Modes.Off.

Setting Mode to Single or Multiple starts the Timer.

Set the Mode to Multiple:

Timer1.Mode = Xojo.Core.Timer.Modes.Multiple

Xojo.Core.Timer.Period

Period As Integer

Specifies the number of milliseconds between calls to the Action event handler.

A period of 0 means to start the timer immediately on the next event loop and is useful for creating a Timer that runs as soon as possible. The Period is not precise as system events or blocking code can delay the call to the Action event handler.

Set the period to 1 second:

Timer1.Period = 1000

Xojo.Core.Timer.Tolerance

Tolerance As Integer

A hint to the system as to how precise (in milliseconds) you need the timer to be, although you may get less tolerance that this depending on what the operating system supports. A value of 0 (the default) means to use the standard for the platform. A value of 100 asks for 100 millisecond tolerance.

Method descriptions


Xojo.Core.Timer.CallNoParams

CallNoParams

Any method that does not have a parameter can be used with CallLater and CancelCall.


Xojo.Core.Timer.CallWithArg

CallWithArg(argument As Variant)

Any method with a single Auto parameter can be used with CallLater or CancelCall.

Event descriptions


Xojo.Core.Timer.Action

Action

Called when the Timer interval is reached, based on the Mode and Period properties.

Timer code always runs in the main thread, shared with UI updates. A long-running process called by a Timer can make the UI unresponsive. In these situations, use a Thread instead.

This code updates an iOSProgressBar:

ProgressBar1.Value = ProgressBar1.Value + 1

' Stop Timer when ProgressBar reaches maximum
If ProgressBar1.Value > ProgressBar1.MaximumValue Then
  Me.Mode = Xojo.Core.Timer.Modes.Off
End If

Notes

Timers run on the main thread.

If you instantiate a Timer in code, you'll need to use AddHandler to direct the Action event to a method. Refer to the AddHandler page for an example.

Compatibility

All project types on all supported operating systems.

See also

Object parent class; AddHandler command