Class ThreadUtils
Represents a series of Thread utility methods.
Inherited Members
Namespace: TriLibCore.Utils
Assembly: TriLibCore.dll
Syntax
public static class ThreadUtils
Methods
RequestNewThreadFor<T>(T, Action<T>, Action<T>, Action<IContextualizedError>, int, string, bool, Action<T>)
Runs the given action on a new Thread if the AssetLoaderContext is async, otherwise, runs it on the main Thread.
Declaration
public static Task RequestNewThreadFor<T>(T context, Action<T> onStart, Action<T> onComplete = null, Action<IContextualizedError> onError = null, int timeout = 0, string name = null, bool startImmediately = true, Action<T> onCompleteSameThread = null) where T : class, IAssetLoaderContext
Parameters
Type | Name | Description |
---|---|---|
T | context | The Context which will be passed to the Action. |
Action<T> | onStart | The Method to execute on the new Thread. |
Action<T> | onComplete | The Method to call on the Main thread when the new Thread has completed. |
Action<IContextualizedError> | onError | The Method to call on the Main Thread when any error occurs. |
int | timeout | The Thread timeout in seconds. |
string | name | The created Thread name. |
bool | startImmediately | Turn on this field to start the Task automatically. |
Action<T> | onCompleteSameThread | Method to call on the created Thread after onStart is completed. |
Returns
Type | Description |
---|---|
Task | The created Thread if Async, otherwise |
Type Parameters
Name | Description |
---|---|
T | Thread context type. |
RunThreadSimple(Action, int, string, bool, int)
Runs the given action on a new Thread (No complete callback, error handling or parameters).
Declaration
public static Task RunThreadSimple(Action onStart, int timeout = 0, string name = null, bool startImmediately = true, int waitMilliseconds = 0)
Parameters
Type | Name | Description |
---|---|---|
Action | onStart | The Method to execute on the new Thread. |
int | timeout | The Thread timeout in seconds. |
string | name | The created Thread name. |
bool | startImmediately | Turn on this field to start the Task automatically. |
int | waitMilliseconds | How many millseconds to wait before running the Thread. |
Returns
Type | Description |
---|---|
Task | The created Thread if Async. |
RunThread<T>(T, ref CancellationToken, Action<T>, Action<T>, Action<IContextualizedError>, int, string, bool)
Runs the given action on a new Thread.
Declaration
public static Task RunThread<T>(T context, ref CancellationToken cancellationToken, Action<T> onStart, Action<T> onComplete = null, Action<IContextualizedError> onError = null, int timeout = 0, string name = null, bool startImmediately = true) where T : IAssetLoaderContext
Parameters
Type | Name | Description |
---|---|---|
T | context | The Context which will be passed to the Action. |
CancellationToken | cancellationToken | The Cancellation Token which can be used by to halt the loading process. |
Action<T> | onStart | The Method to execute on the new Thread. |
Action<T> | onComplete | The Method to call on the Main thread when the new Thread has completed. |
Action<IContextualizedError> | onError | The Method to call on the Main Thread when any error occurs. |
int | timeout | The Thread timeout in seconds. |
string | name | The created Thread name. |
bool | startImmediately | Turn on this field to start the Task automatically. |
Returns
Type | Description |
---|---|
Task | The created Thread if Async. |
Type Parameters
Name | Description |
---|---|
T | Thread context type. |