Table of Contents

Property ExternalCancellationTokenSource

Namespace
Terminal.Gui.Drivers
Assembly
Terminal.Gui.dll

ExternalCancellationTokenSource

Gets or sets an external cancellation token source that can stop the Run(CancellationToken) loop in addition to the runCancellationToken passed to Run(CancellationToken).

CancellationTokenSource? ExternalCancellationTokenSource { get; set; }

Property Value

CancellationTokenSource

Examples

Test scenario with timeout:

var input = new FakeInput();
input.ExternalCancellationTokenSource = new CancellationTokenSource(
    TimeSpan.FromSeconds(30)); // 30-second timeout

// Run will stop if either:
// 1. runCancellationToken is cancelled (normal shutdown)
// 2. 30 seconds elapse (timeout)
input.Run(normalCancellationToken);

Remarks

This property allows external code (e.g., test harnesses like GuiTestContext) to provide additional cancellation signals such as timeouts or hard-stop conditions.

Ownership: The setter does NOT transfer ownership of the CancellationTokenSource. The creator is responsible for disposal. IInput<TInputRecord> implementations should NOT dispose this token source.

How it works: Run(CancellationToken) creates a linked token that responds to BOTH the `runCancellationToken` AND this external token:

var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(
    runCancellationToken,
    ExternalCancellationTokenSource.Token);