Search Results for

    Show / Hide Table of Contents

    Class UnityMainThreadTaskScheduler

    A task scheduler that runs tasks on the Unity main thread via coroutines.

    Inheritance
    System.Object
    System.Threading.Tasks.TaskScheduler
    UnityMainThreadTaskScheduler
    Implements
    System.IDisposable
    Inherited Members
    System.Threading.Tasks.TaskScheduler.TryDequeue(System.Threading.Tasks.Task)
    System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()
    System.Threading.Tasks.TaskScheduler.TryExecuteTask(System.Threading.Tasks.Task)
    System.Threading.Tasks.TaskScheduler.MaximumConcurrencyLevel
    System.Threading.Tasks.TaskScheduler.Current
    System.Threading.Tasks.TaskScheduler.Id
    System.Threading.Tasks.TaskScheduler.UnobservedTaskException
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: IPA.Utilities.Async
    Assembly: IPA.Loader.dll
    Syntax
    public class UnityMainThreadTaskScheduler : TaskScheduler, IDisposable

    Properties

    | Improve this Doc View Source

    Cancelling

    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

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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 Source

    Cancel()

    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

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    Dispose()

    Disposes this object. This puts the object into an unusable state.

    Declaration
    public void Dispose()
    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    GetScheduledTasks()

    Throws a System.NotSupportedException.

    Declaration
    protected override IEnumerable<Task> GetScheduledTasks()
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task>

    nothing

    Overrides
    System.Threading.Tasks.TaskScheduler.GetScheduledTasks()
    Exceptions
    Type Condition
    System.NotSupportedException

    Always.

    | Improve this Doc View Source

    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
    System.Threading.Tasks.TaskScheduler.QueueTask(System.Threading.Tasks.Task)
    Exceptions
    Type Condition
    System.ObjectDisposedException

    Thrown if this object has already been disposed.

    | Improve this Doc View Source

    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
    System.Threading.Tasks.TaskScheduler.TryExecuteTaskInline(System.Threading.Tasks.Task, System.Boolean)
    Exceptions
    Type Condition
    System.ObjectDisposedException

    Thrown if this object has already been disposed.

    Implements

    System.IDisposable

    Extension Methods

    ReflectionUtil.SetField<T, U>(T, String, U)
    ReflectionUtil.GetField<U, T>(T, String)
    ReflectionUtil.SetProperty<T, U>(T, String, U)
    ReflectionUtil.GetProperty<U, T>(T, String)
    ReflectionUtil.InvokeMethod<U, T>(T, String, Object[])
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX