Table of Contents

Class Scheduler

Namespace
Stride.Core.MicroThreading
Assembly
Stride.Core.MicroThreading.dll

Scheduler that manage a group of cooperating MicroThread.

public class Scheduler
Inheritance
Scheduler

Remarks

Microthreading provides a way to execute many small execution contexts who cooperatively yield to each others.

Constructors

Scheduler()

Initializes a new instance of the Scheduler class.

public Scheduler()

Properties

Current

Gets the scheduler associated with current micro thread.

public static Scheduler Current { get; }

Property Value

Scheduler

The scheduler associated with current micro thread.

CurrentMicroThread

Gets the current micro thread (self).

public static MicroThread CurrentMicroThread { get; }

Property Value

MicroThread

The current micro thread (self).

FrameChannel

protected Channel<int> FrameChannel { get; }

Property Value

Channel<int>

MicroThreads

Gets the list of every non-stopped micro threads.

public ICollection<MicroThread> MicroThreads { get; }

Property Value

ICollection<MicroThread>

The list of every non-stopped micro threads.

RunningMicroThread

Gets the current running micro thread in this scheduler through Run().

public MicroThread RunningMicroThread { get; }

Property Value

MicroThread

The current running micro thread in this scheduler.

Methods

Add(Func<Task>, MicroThreadFlags)

Creates a micro thread out of the specified function and schedules it as last micro thread to run in this scheduler. Note that in case of multithreaded scheduling, it might start before this function returns.

public MicroThread Add(Func<Task> microThreadFunction, MicroThreadFlags flags = MicroThreadFlags.None)

Parameters

microThreadFunction Func<Task>

The function to create a micro thread from.

flags MicroThreadFlags

The flags.

Returns

MicroThread

A micro thread.

Create()

Creates a new empty micro thread, that could later be started with Start(Func<Task>, ScheduleMode).

public MicroThread Create()

Returns

MicroThread

A new empty micro thread.

NextFrame()

Yields execution until next frame.

public ChannelMicroThreadAwaiter<int> NextFrame()

Returns

ChannelMicroThreadAwaiter<int>

Task that will resume next frame.

Run()

Runs until no runnable tasklets left. This function is reentrant.

public void Run()

WhenAll(params MicroThread[])

Task that will completes when all MicroThread executions are completed.

public Task WhenAll(params MicroThread[] microThreads)

Parameters

microThreads MicroThread[]

The micro threads.

Returns

Task

A task that will complete when all micro threads are complete.

Yield()

Yields execution. If any other micro thread is pending, it will be run now and current micro thread will be scheduled as last.

public static MicroThreadYieldAwaiter Yield()

Returns

MicroThreadYieldAwaiter

Task that will resume later during same frame.

Events

MicroThreadCallbackEnd

public event EventHandler<SchedulerThreadEventArgs> MicroThreadCallbackEnd

Event Type

EventHandler<SchedulerThreadEventArgs>

MicroThreadCallbackStart

public event EventHandler<SchedulerThreadEventArgs> MicroThreadCallbackStart

Event Type

EventHandler<SchedulerThreadEventArgs>

MicroThreadEnded

public event EventHandler<SchedulerThreadEventArgs> MicroThreadEnded

Event Type

EventHandler<SchedulerThreadEventArgs>

MicroThreadStarted

public event EventHandler<SchedulerThreadEventArgs> MicroThreadStarted

Event Type

EventHandler<SchedulerThreadEventArgs>