Table of Contents

Method RunAsync

Namespace
Terminal.Gui.App
Assembly
Terminal.Gui.dll

RunAsync(IRunnable, CancellationToken, Func<Exception, bool>?)

Asynchronously runs a new Session with the provided runnable view, observing a CancellationToken.

Task<object?> RunAsync(IRunnable runnable, CancellationToken cancellationToken, Func<Exception, bool>? errorHandler = null)

Parameters

runnable IRunnable

The runnable to execute.

cancellationToken CancellationToken

A cancellation token that, when cancelled, will call RequestStop(IRunnable?) to cleanly stop the run loop.

errorHandler Func<Exception, bool>

Optional handler for unhandled exceptions (resumes when returns true, rethrows when null).

Returns

Task<object>

A Task<TResult> that completes when the session ends. The result is the value returned by Run(IRunnable, Func<Exception, bool>?).

Remarks

This method wraps Run(IRunnable, Func<Exception, bool>?) and registers the cancellationToken so that cancellation triggers RequestStop(IRunnable?).

If the token is already cancelled when this method is called, it returns immediately without starting the session.

Cancellation is idempotent: if both the token and an internal RequestStop() fire, only a single shutdown occurs.

RunAsync<TRunnable>(CancellationToken, Func<Exception, bool>?, string?)

Asynchronously runs a new Session creating a IRunnable-derived object of type TRunnable, observing a CancellationToken.

Task<IApplication> RunAsync<TRunnable>(CancellationToken cancellationToken, Func<Exception, bool>? errorHandler = null, string? driverName = null) where TRunnable : IRunnable, new()

Parameters

cancellationToken CancellationToken

A cancellation token that, when cancelled, will call RequestStop(IRunnable?) to cleanly stop the run loop.

errorHandler Func<Exception, bool>

Optional handler for unhandled exceptions (resumes when returns true, rethrows when null).

driverName string

The driver name. If not specified the default driver for the platform will be used.

Returns

Task<IApplication>

A Task representing the asynchronous operation. The IApplication instance is returned for fluent chaining.

Type Parameters

TRunnable

The type of runnable to create and run.

Remarks

This method wraps Run<TRunnable>(Func<Exception, bool>?, string?) and registers the cancellationToken so that cancellation triggers RequestStop().

If the token is already cancelled when this method is called, it returns immediately without starting the session.