Files

28 lines
926 B
C#
Raw Permalink Normal View History

2026-08-04 02:46:53 -07:00
namespace NucleicApp.Services;
/// Isolates WinUI's DispatcherQueue from the renderer state machine and keeps tests portable.
public interface IRendererDispatcher
{
void Post(Action action);
}
public sealed class SynchronizationContextDispatcher : IRendererDispatcher
{
private readonly SynchronizationContext context;
public SynchronizationContextDispatcher(SynchronizationContext? context = null)
{
this.context = context ?? SynchronizationContext.Current
?? throw new InvalidOperationException("renderer has no SynchronizationContext");
}
public void Post(Action action) => context.Post(static state => ((Action)state!).Invoke(), action);
}
public sealed class InlineRendererDispatcher : IRendererDispatcher
{
public static InlineRendererDispatcher Instance { get; } = new();
private InlineRendererDispatcher() { }
public void Post(Action action) => action();
}