Class TaskDirector
A simple control mechanism for distributed TaskBase work across the thread pool. Tasks should be short-lived and can queue up additional work.
Inheritance
Namespace: GDX.Threading
Syntax
public static class TaskDirector
Fields
| Improve this Doc View SourceexceptionOccured
An event invoked when a TaskBase throws an exception.
Declaration
public static Action<Exception> exceptionOccured
Field Value
Type | Description |
---|---|
System.Action<System.Exception> |
inputBlocked
An event invoked during Tick() when user input should be blocked.
Declaration
public static Action<bool> inputBlocked
Field Value
Type | Description |
---|---|
System.Action<System.Boolean> |
logAdded
An event invoked during Tick() with new log content.
Declaration
public static Action<string[]> logAdded
Field Value
Type | Description |
---|---|
System.Action<System.String[]> |
Methods
| Improve this Doc View SourceGetBusyCount()
The number of tasks currently in process or awaiting execution by the thread pool.
Declaration
public static int GetBusyCount()
Returns
Type | Description |
---|---|
System.Int32 | The number of tasks sitting in GDX.Threading.TaskDirector.k_TasksBusy. |
GetQueueCount()
The number of tasks waiting in the queue.
Declaration
public static int GetQueueCount()
Returns
Type | Description |
---|---|
System.Int32 | The number of tasks sitting in GDX.Threading.TaskDirector.k_TasksQueue. |
GetStatus()
Get the status message for the TaskDirector.
Declaration
public static string GetStatus()
Returns
Type | Description |
---|---|
System.String | A pre-formatted status message. |
HasTasks()
Does the TaskDirector have any known busy or queued tasks?
Declaration
public static bool HasTasks()
Returns
Type | Description |
---|---|
System.Boolean | A true/false value indicating tasks. |
Remarks
It's not performant to poll this.
IsBlockingBit(Int32)
Is the TaskDirector blocking tasks with a specific bit?
Declaration
public static bool IsBlockingBit(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Returns
Type | Description |
---|---|
System.Boolean | A true/false value indicating if a BitArray16 index is being blocked. |
Remarks
It isn't ideal to constantly poll this method, ideally this could be used to block things outside of the TaskDirector's control based on tasks running.
Log(String)
Adds a thread-safe log entry to a queue which will be dispatched to logAdded on the Tick() invoking thread.
Declaration
public static void Log(string message)
Parameters
Type | Name | Description |
---|---|---|
System.String | message | The log content. |
QueueTask(TaskBase)
Add a task to the queue, to be later started when possible.
Declaration
public static void QueueTask(TaskBase task)
Parameters
Type | Name | Description |
---|---|---|
TaskBase | task | An established task. |
Remarks
If the task
is already executing it will be added to the known busy list.
Tick()
Update the TaskDirector, evaluating known tasks for work eligibility and execution.
Declaration
public static void Tick()
Remarks
This should occur on the main thread. If the TaskDirector is used during play mode, something needs to call this every global tick. While in edit mode the EditorTaskDirector triggers this method.
UpdateTask(TaskBase)
Evaluate the provided task and update its state inside of the TaskDirector.
Declaration
public static void UpdateTask(TaskBase task)
Parameters
Type | Name | Description |
---|---|---|
TaskBase | task | An established task. |
Remarks
This will add a task to the TaskDirector if it does not already know about it, regardless of the current blocking mode status. Do not use this method to add non executing tasks, they will not be added to the TaskDirector in this way.
Wait()
Wait on the completion of all known tasks, blocking the invoking thread.
Declaration
public static void Wait()
Remarks
Useful to force the main thread to wait for completion of tasks.
WaitAsync()
Asynchronously wait on the completion of all known tasks.
Declaration
public static async Task WaitAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |