IMainThreadDispatcher Interface
Minimal cross-platform interface for marshaling work to the main game thread. Required for GPU operations which must run on the main thread due to platform constraints.
public interface IMainThreadDispatcher
Derived
↳ MainThreadDispatcher
| Properties | |
|---|---|
| IsMainThread | Returns true if called from the main game thread. Always returns false until ProcessQueue() has been called at least once. |
| Methods | |
|---|---|
| ProcessQueue() | Processes all queued main thread work. Called by GameLoop every frame. Also registers the calling thread as the main thread on the first invocation. |
| RunOnMainThread(Action, bool) | Queues work to run on the main thread, or executes it immediately if already on the main thread, before the game loop starts, or after it has shut down. |
| RunOnMainThreadAsync(Action, CancellationToken) | 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. |
| SignalShutdown() | Signals that the game loop has exited. After this call, RunOnMainThreadAsync(Action, CancellationToken) and RunOnMainThread(Action, bool) execute inline on the calling thread rather than enqueuing, preventing post-shutdown deadlocks in background cleanup continuations. Should only be called by the engine's game host infrastructure. |