Platforms to show: All Mac Windows Linux Cross-Platform
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Using a Thread
This example is the version from Thu, 16th Nov 2022.
Project "Using a Thread.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Opening()
System.DebugLog CurrentMethodName
#if TargetWin32
// start timer to yield in order to keep threads running when you use PopupMenus
Static timer As TimerMBS
timer = New TimerMBS(100, False)
timer.Yield = True
#EndIf
End EventHandler
End Class
Class MainWindow Inherits DesktopWindow
Control InfoLabel Inherits DesktopLabel
ControlInstance InfoLabel Inherits DesktopLabel
End Control
Control UIProgress Inherits DesktopProgressBar
ControlInstance UIProgress Inherits DesktopProgressBar
End Control
Control StartButton Inherits DesktopButton
ControlInstance StartButton Inherits DesktopButton
EventHandler Sub Pressed()
UIThread.Start
End EventHandler
End Control
Control UIThread Inherits Thread
ControlInstance UIThread Inherits Thread
EventHandler Sub Run()
Var progressValue As Integer
While progressValue < 100
progressValue = progressValue + 1
System.DebugLog "progressValue: "+str(progressValue)
// Do some long-running process
LongRunningMethod
// Call UpdateUI with any parameters you need. This calls the UpdateUI event handler
// where you can directly access any UI controls on the Window.
// This specifies simple parameters using a Pair
// You can also pass values using a Dictionary
Me.AddUserInterfaceUpdate("UIProgress":progressValue)
Wend
End EventHandler
EventHandler Sub UserInterfaceUpdate(data() as Dictionary)
For Each arg As Dictionary In data
If arg.HasKey("UIProgress") Then
UIProgress.Value = arg.Value("UIProgress").IntegerValue
UIProgress.Refresh(true)
End If
Next
End EventHandler
End Control
Control Label1 Inherits DesktopLabel
ControlInstance Label1 Inherits DesktopLabel
End Control
EventHandler Sub Closing()
UIThread.Stop
End EventHandler
Sub LongRunningMethod()
// This method just wastes some CPU time to simulate an actual method
// that may be performing a lengthy process.
Var waitUntil As Integer = System.Ticks + 15
While System.Ticks < waitUntil
Wend
End Sub
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
The items on this page are in the following plugins: MBS Win Plugin.