Thread.Run method

From Xojo Documentation



Supported for all project types and targets.

Executes the thread’s Run event handler.


The following example illustrates how to update an interface using a Timer and a Thread. The computation is done in the Thread but the interface is updated via the Timer in the main thread.

The user interface has a PushButton, ProgressBar, Timer and Thread object on the Window.

The Action event of the PushButton gives the ProgressBar an ititial value and sets the mode of the Timer to Multiple. The Timer periodically checks on the status of the ProgressBar.

This is the code in the PushButton Action event hander:

ProgressBar1.Value = 0
Timer1.Mode = Timer.ModeMultiple // periodically check ProgressBar and update the interface

The Run event handler of the Thread is what calculates the value for the ProgressBar. ProgressValue is a property (Double) of the window.

progressValue = 0

While progressValue < 100 // if not the Maximum...
// recompute progressValue, a property of the Window
progressValue = progressValue + 1

// do nothing for 1/4 second or so so folks can see the actual progress
Dim waitUntil As Integer = Ticks + 15
While ticks < waitUntil


The Timer periodically checks the state of the ProgressBar. If it has not reached its maximum value, it updates it with the computed value.

If ProgressBar1.Value >= ProgressBar1.Maximum then // tests the ProgressBar value
ProgressBar1.Value = ProgressBar1.Maximum
Me.Mode = Timer.ModeOff // turns off the checking/updating
Else // if not maximum
// updates the interface with the current value that was updated by the thread
ProgressBar1.Value = progressValue
End If