Thread.Run method
From Xojo Documentation
This item was deprecated in version 2019r2. Please use Thread.Start as a replacement. |
Executes the thread’s Run event handler.
Examples
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:
Timer1.Mode = Timer.ModeMultiple // periodically check ProgressBar and update the interface
Thread1.Run
The Run event handler of the Thread is what calculates the value for the ProgressBar. ProgressValue is a property (Double) of the window.
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
Wend
Wend
The Timer periodically checks the state of the ProgressBar. If it has not reached its maximum value, it updates it with the computed 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