Class TaskBase
The base of a task used by TaskDirector.
Inheritance
Namespace: GDX.Threading
Syntax
public abstract class TaskBase
Fields
| Improve this Doc View Sourcecompleted
An event that is triggered when the TaskBase has finished its execution.
Declaration
public Action<TaskBase> completed
Field Value
Type | Description |
---|---|
System.Action<TaskBase> |
Remarks
It is super important to remember that subscribed actions will invoke off of the main thread. Any logic that requires the main thread will not work. Many of Unity's APIs are not safe for this.
completedMainThread
An event that is triggered once the TaskBase has finished, during the next tick of the TaskDirector.
Declaration
public Action<TaskBase> completedMainThread
Field Value
Type | Description |
---|---|
System.Action<TaskBase> |
Remarks
This is a safe way to do work which requires being executed on the main thread.
m_Bits
The TaskBase's descriptive bits.
Declaration
protected BitArray16 m_Bits
Field Value
Type | Description |
---|---|
BitArray16 |
m_BlockingBits
A quick set of bits used to describe tasks that should be blocked when m_BlockingModes contains Bits. The opposing TaskBase will have its m_Bits checked for positives that match.
Declaration
protected BitArray16 m_BlockingBits
Field Value
Type | Description |
---|---|
BitArray16 |
Remarks
If any of them are the sam
m_BlockingModes
The TaskBase's blocking modes for other tasks.
Declaration
protected TaskBase.BlockingModeFlags m_BlockingModes
Field Value
Type | Description |
---|---|
TaskBase.BlockingModeFlags |
m_Exception
The exception that occured.
Declaration
protected Exception m_Exception
Field Value
Type | Description |
---|---|
System.Exception |
Remarks
See IsFaulted().
m_IsLogging
Should the task report information to the TaskDirector log.
Declaration
protected bool m_IsLogging
Field Value
Type | Description |
---|---|
System.Boolean |
m_Name
The user-friendly name of the task, used by different feedback systems.
Declaration
protected string m_Name
Field Value
Type | Description |
---|---|
System.String |
Remarks
It's important to set this in inherited constructors.
Methods
| Improve this Doc View SourceComplete()
Forcibly completes the task on the given thread where the method is invoked.
Declaration
public void Complete()
Remarks
This will also forcibly tick the TaskDirector upon completion to trigger callbacks. You should not be using this unless you have an explicit purpose too.
DoWork()
The core logic to be defined for a task.
Declaration
public abstract void DoWork()
Enqueue()
Enqueue the current TaskBase with the TaskDirector for execution.
Declaration
public void Enqueue()
GetBits()
Gets the associated BitArray16 with this task.
Declaration
public BitArray16 GetBits()
Returns
Type | Description |
---|---|
BitArray16 | The defined flags. |
GetBlockedBits()
Gets the BitArray16 to evaluate other tasks against.
Declaration
public BitArray16 GetBlockedBits()
Returns
Type | Description |
---|---|
BitArray16 | The defined bits. |
GetBlockingModes()
Returns the TaskBase.BlockingModeFlags used to determine other task execution.
Declaration
public TaskBase.BlockingModeFlags GetBlockingModes()
Returns
Type | Description |
---|---|
TaskBase.BlockingModeFlags | A set of flags indicating if other tasks should be able to start execution. |
GetException()
Returns the System.Exception that was created when the task faulted.
Declaration
public Exception GetException()
Returns
Type | Description |
---|---|
System.Exception | An System.Exception object. |
Remarks
See IsFaulted().
GetName()
Gets the user-friendly name of the task.
Declaration
public string GetName()
Returns
Type | Description |
---|---|
System.String | The defined System.String name of the task. |
IsBlockingAllTasks()
Does this TaskBase block all other tasks after it from starting execution?
Declaration
public bool IsBlockingAllTasks()
Returns
Type | Description |
---|---|
System.Boolean | true if this task blocks all after it, otherwise false. |
Remarks
This will keep all tasks after it sitting waiting for this task to complete.
IsBlockingBits()
Does this TaskBase block other tasks from executing based on its m_BlockingBits?
Declaration
public bool IsBlockingBits()
Returns
Type | Description |
---|---|
System.Boolean | true if this tasks blocks based on bits, otherwise false. |
IsBlockingSameName()
Does this TaskBase block all other tasks of the same name from starting during its execution?
Declaration
public bool IsBlockingSameName()
Returns
Type | Description |
---|---|
System.Boolean | true if this tasks blocks same named tasks, otherwise false. |
IsBlockingUserInterface()
Should the execution of this TaskBase prevent the user from providing input to the user interface?
Declaration
public bool IsBlockingUserInterface()
Returns
Type | Description |
---|---|
System.Boolean | true if this task should prevent user input, otherwise false. |
Remarks
This directly relates to the inputBlocked, altering the count used to trigger that particular event.
IsDone()
Is the TaskBase finished executing?
Declaration
public bool IsDone()
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the execution phase of the task has been completed. This will be true if an exception has occured. |
IsExecuting()
Is the TaskBase currently executing on the thread pool?
Declaration
public bool IsExecuting()
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the task is executing, otherwise false. |
IsFaulted()
Did an exception occur while executing off thread?
Declaration
public bool IsFaulted()
Returns
Type | Description |
---|---|
System.Boolean | Returns true if an exception occured. |
Run()
Execute task logic.
Declaration
public void Run()