Platforms to show: All Mac Windows Linux Cross-Platform

/Util/Preemptive Threading/Test Threading


You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/Preemptive Threading/Test Threading

This example is the version from Sat, 3rd Mar 2023.

Project "Test Threading.xojo_binary_project"
Class App Inherits ConsoleApplication
EventHandler Function Run(args() as String) As Integer System.DebugLog CurrentMethodName Dim r As Boolean done = False Dim d As WorkDelegate = AddressOf ThreadModule.Work r = CallDelegateOnPreemptiveThreadMBS(d) System.DebugLog "Called." While Not done System.DebugLog "waiting..." SleepMBS(0.1) Wend System.DebugLog "done!" End EventHandler
End Class
Module ThreadModule
Delegate Sub WorkDelegate()
Sub Work() // this runs in pre-emptive thread // may crash in debugger #Pragma BackgroundTasks False #Pragma BreakOnExceptions False #Pragma NilObjectChecking False #Pragma StackOverflowChecking False // wait a bit SleepMBS(1.0) done = True End Sub
Note "Warning"
Experimental function to play with preemptive-threads in Xojo apps. Some rules: * No objects, no strings, no arrays * Use Ptr, not Memoryblocks * Crashes in debugger, so only use in built app * Use #Pragma BackgroundTasks False * Use #Pragma BreakOnExceptions False * Use #Pragma StackOverflowChecking False * Use #Pragma NilObjectChecking False * No exceptions * Delegate must be stored in global variable to avoid it getting freed early. * You can pass up to one ptr as data parameter. uses thread pool on iOS, macOS and Windows. Otherwise regular threads.
Property done As Boolean
End Module
End Project

See also:

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


The biggest plugin in space...