Class UnityMainThreadTaskScheduler
A task scheduler that runs tasks on the Unity main thread via coroutines.
Inheritance
Implements
Inherited Members
Namespace: IPA.Utilities.Async
Assembly: IPA.Loader.dll
Syntax
public class UnityMainThreadTaskScheduler : TaskScheduler, IDisposable
Properties
| Improve this Doc View SourceCancelling
Gets whether or not this scheduler is in the process of shutting down.
Declaration
public bool Cancelling { get; }
Property Value
Type | Description |
---|---|
System.Boolean | true if the scheduler is shutting down, false otherwise |
Default
Gets the default main thread scheduler that is managed by BSIPA.
Declaration
public static UnityMainThreadTaskScheduler Default { get; }
Property Value
Type | Description |
---|---|
UnityMainThreadTaskScheduler | a scheduler that is managed by BSIPA |
Factory
Gets a factory for creating tasks on Default.
Declaration
public static TaskFactory Factory { get; }
Property Value
Type | Description |
---|---|
System.Threading.Tasks.TaskFactory | a factory for creating tasks on the default scheduler |
IsRunning
Gets whether or not this scheduler is currently executing tasks.
Declaration
public bool IsRunning { get; }
Property Value
Type | Description |
---|---|
System.Boolean | true if the scheduler is running, false otherwise |
YieldAfterTasks
Gets or sets the number of tasks to execute before yielding back to Unity.
Declaration
public int YieldAfterTasks { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | the number of tasks to execute per resume |
YieldAfterTime
Gets or sets the amount of time to execute tasks for before yielding back to Unity. Default is 0.5ms.
Declaration
public TimeSpan YieldAfterTime { get; set; }
Property Value
Type | Description |
---|---|
System.TimeSpan | the amount of time to execute tasks for before yielding back to Unity |
Methods
| Improve this Doc View SourceCancel()
Cancels the scheduler. If the scheduler is currently executing tasks, that batch will finish first. All remaining tasks will be left in the queue.
Declaration
public void Cancel()
Exceptions
Type | Condition |
---|---|
System.ObjectDisposedException | if this scheduler is disposed |
System.InvalidOperationException | if the scheduler is not running |
Coroutine()
When used as a Unity coroutine, runs the scheduler. Otherwise, this is an invalid call.
Declaration
public IEnumerator Coroutine()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | a Unity coroutine |
Remarks
Do not ever call UnityEngine.MonoBehaviour.StopCoroutine(System.Collections.IEnumerator) on this coroutine, nor UnityEngine.MonoBehaviour.StopAllCoroutines on the behaviour hosting this coroutine. This has no way to detect this, and this object will become invalid.
If you need to stop this coroutine, first call Cancel(), then wait for it to exit on its own.
Exceptions
Type | Condition |
---|---|
System.ObjectDisposedException | if this scheduler is disposed |
System.InvalidOperationException | if the scheduler is already running |
Dispose()
Disposes this object. This puts the object into an unusable state.
Declaration
public void Dispose()
Dispose(Boolean)
Disposes this object.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | whether or not to dispose managed objects |
GetScheduledTasks()
Throws a System.NotSupportedException.
Declaration
protected override IEnumerable<Task> GetScheduledTasks()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task> | nothing |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Always. |
QueueTask(Task)
Queues a given System.Threading.Tasks.Task to this scheduler. The System.Threading.Tasks.Task must be scheduled for this System.Threading.Tasks.TaskScheduler by the runtime.
Declaration
protected override void QueueTask(Task task)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.Tasks.Task | task | the System.Threading.Tasks.Task to queue |
Overrides
Exceptions
Type | Condition |
---|---|
System.ObjectDisposedException | Thrown if this object has already been disposed. |
TryExecuteTaskInline(Task, Boolean)
Runs the task inline if the current thread is the Unity main thread.
Declaration
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.Tasks.Task | task | the task to attempt to execute |
System.Boolean | taskWasPreviouslyQueued | whether the task was previously queued to this scheduler |
Returns
Type | Description |
---|---|
System.Boolean | false if the task could not be run, true if it was |
Overrides
Exceptions
Type | Condition |
---|---|
System.ObjectDisposedException | Thrown if this object has already been disposed. |