Platforms to show: All Mac Windows Linux Cross-Platform

/Util/Threads/Thread Priority


Required plugins for this example: MBS Util Plugin

Last modified Tue, 9th Mar 2026.

You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /Util/Threads/Thread Priority

Download this example: Thread Priority.zip

Project "Thread Priority.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits DesktopWindow
Control Button1 Inherits DesktopButton
ControlInstance Button1 Inherits DesktopButton
EventHandler Sub Pressed() if Thread1.ThreadState = Thread.ThreadStates.NotRunning then Thread1.run Else beep End If End EventHandler
End Control
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run() Var EndTime As Double = Microseconds + 10 * 1000 * 1000 // we set the QOS for this thread var e as integer = SetQOSClassMBS(SelectedQOS) Var q As Integer = GetQOSClassMBS Me.AddUserInterfaceUpdate New Dictionary("message": "Started with QOS: " + q.ToString) counter = 0 wasteTime While EndTime > Microseconds wasteTime Wend Me.AddUserInterfaceUpdate New Dictionary("message": "Finished "+str(counter / 1000000.0, "0.0")) End EventHandler
EventHandler Sub UserInterfaceUpdate(data() as Dictionary) For Each d As Dictionary in data Listbox1.AddRow d.Value("message").StringValue Next End EventHandler
End Control
Control ListBox1 Inherits DesktopListBox
ControlInstance ListBox1 Inherits DesktopListBox
End Control
Control PopupMenu1 Inherits DesktopPopupMenu
ControlInstance PopupMenu1 Inherits DesktopPopupMenu
EventHandler Sub Opening() me.RemoveAllRows Me.AddRow "Unspecified" Me.AddRow "Backgound" // like backup Me.AddRow "Utility" // like menu utility Me.AddRow "Default" Me.AddRow "User Initiated" me.AddRow "User Interactive" // front app handling user input Me.SelectedRowIndex = 3 End EventHandler
EventHandler Sub SelectionChanged(item As DesktopMenuItem) SelectedQOS = Me.SelectedRowIndex System.DebugLog "SelectedQOS: "+SelectedQOS.ToString End EventHandler
End Control
EventHandler Sub Opening() counter = 0 End EventHandler
Property SelectedQOS As Integer
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"
MenuItem WindowMenu = "Window"
MenuItem HelpMenu = "&Help"
End MenuBar
Sign
End Sign
Module Module1
Const QOS_CLASS_BACKGROUND = 1
Const QOS_CLASS_DEFAULT = 3
Const QOS_CLASS_UNSPECIFIED = 0
Const QOS_CLASS_USER_INITIATED = 4
Const QOS_CLASS_USER_INTERACTIVE = 5
Const QOS_CLASS_UTILITY = 2
Sub wasteTime() // counter work for the thread #Pragma DisableBackgroundTasks For i As Integer = 1 To 1000000 counter = counter + 1 Next End Sub
Property counter As Integer
End Module
End Project

Download this example: Thread Priority.zip

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...