Thread
Description
- Derived from
-
Disposable abstract
INativeHandle
The Thread represents a background thread.
To create and run a background thread, the following steps are necessary:
-
Creates a new instance of Thread.
-
Configure the optional Argument, Name and Priority properties.
-
Set the thread main function with ThreadMain.
-
Call the Start method to initialize and run the background thread.
-
Configure the LogOnError property at any time during the thread’s lifetime.
-
Call the Stop method to tell the background thread to terminate gracefully.
-
Call the Join method to actually wait until the thread has terminated.
-
Finally, dispose the thread to free up system resources. Upon disposal, the Stop and Join method will be called.
The Create method can be used as a shortcut for steps 1, 2, 3 and 5.
Public / Methods
Join
Waits until this thread has terminated.
If the thread has already been terminated, the method returns silently.
SingleThreadedMode
Forces the Tinman 3D SDK to run in single-threaded mode, where the following methods emulate the semantic of multi-threading while using only the calling sole application thread:
This method must be called before the Tinman 3D library is initialized (see TinmanModule.Initialize), otherwise undefined behaviour may occur.
Single-threaded emulation mode is intended to be used in specific cases, where the runtime environment does not support threads (for example, a client-side WASM module in a browser) or when reproducible behaviour is required (when debugging). With emulation, the same code may run on both multi-threaded and single-threaded environments. However, running in single-threaded emulation mode will most likely introduce significant performance degradation as well as reduced responsiveness of the main application thread.
- See also
SingleThreadedTick
This method runs the single-threaded emulation mode.
The Tinman 3D SDK already calls this method. Client code may perform additional calls while waiting to an asynchronous operation to finish, in order to improve responsiveness of the sole application thread.
- See also
Start
Starts this thread.
The method creates a new background thread which will execute the Run
method of the given IThreadMain object (see ThreadMain property).
If the thread has already been started, the method silently returns.
Stop
Stops the thread.
The thread will be signalled to stop. It will not have been terminated when this method returns. Use the Join method for waiting for the termination of the thread.
If the thread has already been stopped, the method returns silently.
Public / Attributes
Argument
The argument object to pass to the thread main method.
The argument object may only be set before Start is called.
Defaults to null
.
- See also
Error
The error info of the exception that has occurred in the Run
method of the threads main method (see IThreadMain).
LogOnError
Output a log message when the thread terminates due to an unhandled exception?
Defaults to true
.
Priority
Gets or sets the thread priority.
The thread priority may only be set before Start is called.
Defaults to ThreadPriority.Normal.
ThreadMain
Gets or sets the thread main method.
The thread main method must be set before Start is called.