public sealed class MainThreadDispatcherWork that has to happen on one particular thread, queued until that thread drains it.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Some calls are not thread-agnostic no matter how good the job system is. A GL context belongs to the thread that made it current; the platform window APIs on macOS and Windows insist on the thread that owns the message loop; .NET Hot Reload applies its deltas from one place. This is where that work goes, and Drain at a defined frame point is where it happens.
Draining at defined points rather than opportunistically is the reason this exists at all instead of a lock. A queue that is drained between the simulation and the render is a queue whose effects land in one predictable place, which is what makes a race between a worker's request and the main thread's state impossible rather than unlikely.
Fields and properties (3)
public int ThreadIdThe thread this dispatcher drains on.
public bool IsMainThreadWhether the calling thread is the one this dispatcher drains on.
public int PendingCountHow many items are waiting. Racy; for overlays and assertions.
Methods (7)
public MainThreadDispatcher()Creates a dispatcher bound to the calling thread.
public MainThreadDispatcher(int threadId)Creates a dispatcher bound to a chosen thread.
public void Post(Action action)Queues work for the main thread and returns immediately.
public void Post<TState>(Action<TState> action, TState state)Queues work for the main thread, with state, and returns immediately.
public void Send(Action action)Queues work for the main thread and waits for it, rethrowing whatever it threw.
public int Drain()Runs everything queued so far. Main thread only.
public void AssertMainThread()Throws unless the calling thread is the bound one.
Used by (6)
- AppBuilderVixen.App.Hosting
- AppServicesVixen.App.Hosting
- MainThreadDispatcherTestsVixen.Core.Threading.Tests
- VixenApplicationVixen.App.Hosting
- PostingGameVixen.App.Tests
- VixenApplicationTestsVixen.App.Tests