Primary APIs:
DispatcherDispatcherPriorityDispatcherOptionsDispatcherOperation / DispatcherOperation<T>DispatcherOperationStatusDispatcherPriorityAwaitable / DispatcherPriorityAwaitable<T>DispatcherTimerDispatcherFrameRelated event args/types:
DispatcherEventArgsDispatcherUnhandledExceptionEventArgsDispatcherUnhandledExceptionFilterEventArgsUse these APIs to guard thread access and queue flow:
CheckAccess()VerifyAccess()SupportsRunLoopsRunJobs(...)HasJobsWithPriority(...)Dispatcher starvation tuning surface:
DispatcherOptionsDispatcherOptions.InputStarvationTimeoutPattern:
if (!Dispatcher.UIThread.CheckAccess())
{
await Dispatcher.UIThread.InvokeAsync(UpdateUi);
return;
}
Dispatcher.UIThread.VerifyAccess();
UpdateUi();
Useful DispatcherPriority members:
MaxValueFromValue(int value)Validate(priority, parameterName)CompareTo(...)Equals(...)GetHashCode()SystemIdle, Inactive, InvalidUiThreadRender, BeforeRender, AsyncRenderTargetResizeOperator semantics are explicit and order-aware:
operator ==operator !=operator <operator >operator <=operator >=operator intoperator DispatcherPriorityUse DispatcherPriority.Validate(...) on externally supplied numeric values before scheduling.
InvokeAsync(...) returns DispatcherOperation / DispatcherOperation<T>.
Operational members:
StatusPriorityAbort()GetTask()Wait()Completed / AbortedTyped operation result and state APIs:
ResultDispatcherOperation<T>.ResultDispatcherOperationStatusPattern:
var op = Dispatcher.UIThread.InvokeAsync(
() => ComputeUiResult(),
DispatcherPriority.Background);
await op.GetTask();
if (op.Status == DispatcherOperationStatus.Completed)
{
var value = op.Result;
_ = value;
}
Guidance:
await op.GetTask() in async flows,Wait() only for narrow synchronous boundaries.DispatcherPriorityAwaitable APIs:
OnCompleted(...)IsCompletedGetResult()Generic variant:
DispatcherPriorityAwaitable<T>DispatcherPriorityAwaitable<T>.GetResult()These are used by AwaitWithPriority(...) paths to continue on the dispatcher with a selected priority.
Main-loop control APIs:
ShutdownStartedShutdownFinishedPushFrame(DispatcherFrame frame)ExitAllFrames()DisableProcessing()DispatcherProcessingDisabledNested-frame type:
DispatcherFrameDispatcherFrame.ContinueUse nested frames sparingly; they can re-enter app code and complicate invariants.
DispatcherTimer constructors and members:
DispatcherTimer()DispatcherTimer(DispatcherPriority priority)DispatcherTimer(TimeSpan interval, DispatcherPriority priority, EventHandler callback)TagTickStart(), Stop()Run(...), RunOnce(...)Pattern:
var timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Background, (_, _) =>
{
RefreshClock();
});
timer.Tag = "clock";
timer.Start();
Dispatcher exception flow uses:
DispatcherEventArgsDispatcherUnhandledExceptionEventArgsDispatcherUnhandledExceptionFilterEventArgsDispatcherUnhandledExceptionFilterEventArgs.RequestCatchUse handlers for telemetry and controlled fallback, not normal branching.
Background.
RunJobs(...) only in controlled test/simulation paths.
CheckAccess()/VerifyAccess() usage and queued priority.DispatcherOperationStatus and whether the dispatcher run loop is active.HasJobsWithPriority(...).PushFrame(...) usage and ensure ExitAllFrames() is called in shutdown paths.