Press on the image to return to the main documentation page.
Threading
Written by Andrew Graham
Basic4Android applications have only one thread, the main or GUI (Graphical User Interface) thread that, not surprisingly, handles the user interface (and everything else). Using this library you can create additional threads that operate (apparently) in parallel alongside each other and the GUI thread. Threads can be useful to keep the user interface alive while performing a long sequence of computations or while waiting for something to happen.
Such threads are not allowed to manipulate GUI elements directly but this can be achieved by the Thread.RunOnGuiThread method that runs a Sub on the main GUI thread.
This library contains a Thread object that runs the Basic4Android Sub on a separate thread, a Lock object to facilite orderly use of resources by different threads and can also be used to synchronise threads and an Exception object to give more flexibility in handling exceptions than is native to Basic4Android.
This is the Exception object that provides facilites for handling exceptions. As Basic4Android has a more basic Exception object this one is called ExceptionEx to avoid a name conflict.
This is the Thread object that actually runs a Basic4Android Sub on a separate thread. Normally Threads should be created as Process objects so they will persist as long as the application exists. This will make their behaviour easier to predict and control rather them being Activity objects which will need recreating when an activity resumes which might leave orphan threads running that could cause unexpected problems.
Events:
Ended(endedOK As Boolean, error As String) 'The thread has terminated. If endedOK is False error holds the reason for failure