Skip to content

IMainThreadDispatcher.RunOnMainThreadAsync(Action, CancellationToken) Method

Definition

Namespace: Brine2D.Threading

Queues work to run on the main thread and returns a System.Threading.Tasks.Task that completes when the work finishes. Executes inline if already on the main thread, before the game loop starts, or after SignalShutdown() has been called.

C#
System.Threading.Tasks.Task RunOnMainThreadAsync(System.Action work, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

work System.Action

cancellationToken System.Threading.CancellationToken

Returns

System.Threading.Tasks.Task

Remarks

Cancellation only abandons the \<em>wait\</em> — the work item remains in the queue and will still execute on the next ProcessQueue() drain. Do not pass a cancellation token when the work must always run \(e\.g\., final state swaps\).