Class UnityMainThreadTaskScheduler
A task scheduler that runs tasks on the Unity main thread via coroutines.
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 |
|---|---|
| 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 TaskScheduler Default { get; }
Property Value
| Type | Description |
|---|---|
| TaskScheduler | 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 |
|---|---|
| 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 |
|---|---|
| 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 |
|---|---|
| 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 |
|---|---|
| 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 |
|---|---|
| ObjectDisposedException | if this scheduler is disposed |
| 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 |
|---|---|
| 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 |
|---|---|
| ObjectDisposedException | if this scheduler is disposed |
| 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 |
|---|---|---|
| Boolean | disposing | whether or not to dispose managed objects |
GetScheduledTasks()
Throws a NotSupportedException.
Declaration
protected override IEnumerable<Task> GetScheduledTasks()
Returns
| Type | Description |
|---|---|
| IEnumerable<Task> | nothing |
Overrides
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | Always. |
QueueTask(Task)
Queues a given Task to this scheduler. The Task must> be scheduled for this TaskScheduler by the runtime.
Declaration
protected override void QueueTask(Task task)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | the Task to queue |
Overrides
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown if this object has already been disposed. |
TryExecuteTaskInline(Task, Boolean)
Rejects any attempts to execute a task inline.
Declaration
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | the task to attempt to execute |
| Boolean | taskWasPreviouslyQueued | whether the task was previously queued to this scheduler |
Returns
| Type | Description |
|---|---|
| Boolean | false |
Overrides
Remarks
This task scheduler always runs its tasks on the thread that it manages, therefore it doesn't make sense to run it inline.
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown if this object has already been disposed. |