UserGuide

Web Timer

From Xojo Documentation

The Timer executes some code once or repeatedly after a period of time has passed.

Timer is covered in more detail in the UserGuide:Timers topic.

The Web Timer is very similar to the standard Timer control. The important difference is that the Web Timer can be server-side or client side meaning that it would be part of the webpage it's on.

A Web Timer can be used to update controls on the page, for example. A standard Timer control will only execute server-side, so it cannot contact the client.

Events

Run

The Run event is called when the Timer period is reached.

Properties

RunMode

Indicates if the Timer is Off, Single or Multiple.

Period

The number of milliseconds between calls to the Action event.

Methods

Reset

Call this to reset and restart the Timer.

Usage

The Web Timer provides the same functionality as the Desktop Timer control. This example updates the value on a label (SecondsPassedLabel) on the web page using the WebTimer. This code in the WebTimer updates the label:

SecondsPassedLabel.Value = Str(SecondsPassedLabel.Value.ToInteger + 1)

You can also add a button to start and stop the timer. This code is in a Button's Pressed event:

If Me.Caption = "Start" Then
Timer1.Mode = WebTimer.RunModes.Multiple
Me.Caption = "Stop" // button caption
Else
SecondsPassedLabel.Value = "0"
Timer1.Mode = WebTimer.RunModes.Off // Turn off the timer
Me.Caption = "Start"
End If

Example Projects

These project demonstrate ways that a Web Timer is used to update the UI:

  • Examples/Web/Controls/Progress
  • Examples/Web/Controls/TimerExample
  • Examples/Web/Controls/ThreadProgress

See Also

WebTimer class; UserGuide:Web UI topic