RunicModelContext class

Namespace Runic.Navigation · Runic.Navigation 0.7.0-preview.5

public sealed class RunicModelContext : IRunicModelContext, IAsyncDisposable, IRunicModelContextLifetime

Inherits or implements IRunicModelContext, IAsyncDisposable, IRunicModelContextLifetime.

A host-neutral serial execution context for a ViewModel graph.

Constructors

RunicModelContext

public RunicModelContext()

Creates a model context that writes unhandled turn failures to Trace.

RunicModelContext

public RunicModelContext(ILogger<RunicModelContext>? logger)

Creates a model context that logs unhandled turn failures to logger.

Parameters

logger

The logger, or null for Trace output.

Properties

Closed

public CancellationToken Closed { get; }

Gets a token cancelled after the context stops accepting work and before queued work is rejected.

Remarks

Callbacks run synchronously on the closing thread. Their exceptions are reported through RunicModelContext.UnhandledTurnException and do not interrupt shutdown. The token remains usable after disposal.

IsExecuting

public bool IsExecuting { get; }

Gets whether the calling code is executing one of this context's turns.

Documentation from IRunicModelContext.IsExecuting.

Methods

DisposeAsync

public ValueTask DisposeAsync()

Rejects queued work and completes after a currently executing synchronous turn returns. A running turn cannot be interrupted. Rejected invocations fault with ObjectDisposedException; rejected posted turns are reported through RunicModelContext.UnhandledTurnException.

InvokeAsync

public ValueTask InvokeAsync(Action turn, CancellationToken cancellationToken = default)

Runs a short synchronous turn in this context.

Documentation from IRunicModelContext.InvokeAsync.

InvokeAsync

public ValueTask<T> InvokeAsync<T>(Func<T> turn, CancellationToken cancellationToken = default)

Runs a short synchronous turn in this context and returns its result.

Documentation from IRunicModelContext.InvokeAsync.

TryPost

public bool TryPost(Action turn)

Queues a short synchronous turn when the context is still accepting work.

Documentation from IRunicModelContext.TryPost.

Events

UnhandledTurnException

public event Action<Exception>? UnhandledTurnException

Receives exceptions thrown by turns queued with IRunicModelContext.TryPost, and an ObjectDisposedException for each posted turn dropped by disposal.

Documentation from IRunicModelContext.UnhandledTurnException.