Thread object
Previous  Next

The Thread object provides the following Methods, Properties and Events.


Methods

Abort : Stop the thread immediately. This will cause an error in the Sub that is executing as a thread that may be trapped using ErrorLabel. Any cleanup required due to the, probable, early termination of the thread can then be performed.

FireDebugEvent : Raises the DebugEvent event.

FireThreadEvent : Raises the ThreadEvent event.

Join (mSecs As Integer) : Join takes a parameter in mSecs and returns the thread state, true = stopped : false = running. 0 returns immediately with the state of the thread, -1 waits forever for the the thread to stop. For any positive value the thread will wait for the timeout to expire OR the thread to stop. Note that IF any value other than 0 is used AND it is the main thread invoking Join AND the thread being Joined is firing events THEN that thread will be blocked if it raises an event while the Join is timing out because the thread event waits for the main GUI thread to update but the main thread is blocked by the join wait so neither thread  runs until the wait expires and lets the thread event complete.

New1(B4Pobject(1)) : Creates a new instance of the Threader object.

RunLocked0(Sub As String) : Runs the Sub, which must have no parameters, in locked mode so it may not be interrupted. Returns whatever Sub returns, if anything.

RunLocked1(Sub As String, a As Parameter,) : Runs the Sub, which must have one parameter, in locked mode so it may not be interrupted. Returns whatever Sub returns, if anything. Param is whatever can be accepted by Sub as a parameter.

RunLocked2(Sub As String, a As Param, b  As Param) : Runs the Sub, which must have two parameters, in locked mode so it may not be interrupted. Returns whatever Sub returns, if anything. Param is whatever can be accepted by Sub as a parameter.

RunLocked3(Sub As String, a As Param, b  As Param, c As Param) : Runs the Sub, which must have three parameters, in locked mode so it may not be interrupted. Returns whatever Sub returns, if anything. Param is whatever can be accepted by Sub as a parameter.

Sleep(mSecs As Integer) : This  is the same as the B4PPC Sleep method and suspends the thread ,using no CPU resources, for the given period.

Yield : This is shorthand for Sleep(0) and gives up the rest of a thread's timeslice. However the thread is immediately rescheduled to run at the next opportunity.

Start(Sub As String) : Runs the Sub starting it as a separate thread. Returns true if the thread was started false if it wasn't - probably because it was already running.


Properties

I signifies readable and O signifies settable..

ControlRef : Thread [I] : The underlying .NET Thread object. This is not usable in Basic4PPC code.

DLLversion: Integer [I] : The version number of this library.

IsBackground: Integer [I/O] : If true then the thread is a background thread, if false a foreground thread. The default is a background thread.

Priority: Integer [I/O] : Value between 0 and 4 determining the thread priority. Lowest 0 : BelowNormal 1 : Normal 2 : AboveNormal 3 : Highest 4. The default is a Normal.


Events

DebugEvent: Occurs when the FireDebugEvent method is called. The event Sub runs on the main GUI thread and the caller of FireDebugEvent is suspended until the DebugEvent Sub returns.

ThreadEvent: Occurs when the FireThread Event method is called. The event Sub runs on the main GUI thread and the caller of FireThreadEvent is suspended until the ThreadEvent Sub returns.