Table of Contents

Method Run

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

Run(CancellationToken)

Runs the input loop, continuously reading input and placing it into the queue provided by Initialize(ConcurrentQueue<TInputRecord>).

void Run(CancellationToken runCancellationToken)

Parameters

runCancellationToken CancellationToken

The primary cancellation token that stops the input loop. Provided by Terminal.Gui.App.MainLoopCoordinator<TInputRecord> and triggered during application shutdown.

Remarks

Threading: This method runs on a dedicated input thread created by StartInputTaskAsync(IApplication). and blocks until cancellation is requested. It should never be called from the main UI thread.

Cancellation: The loop stops when either runCancellationToken or ExternalCancellationTokenSource (if set) is cancelled.

Base Implementation: Run(CancellationToken) provides the standard loop logic:

while (!cancelled)
{
    while (Peek())  // Check for available input
    {
        foreach (var input in Read())  // Read all available
        {
            inputQueue.Enqueue(input);  // Store for processing
        }
    }
    Task.Delay(20ms);  // Throttle to ~50 polls/second
}

Testing: For ITestableInput<TInputRecord> implementations, test input injected via AddInput(TInputRecord) flows through the same Peek/Read pipeline.

Exceptions

OperationCanceledException

Thrown when runCancellationToken or ExternalCancellationTokenSource is cancelled. This is the normal/expected means of exiting the input loop.

InvalidOperationException

Thrown if Initialize(ConcurrentQueue<TInputRecord>) was not called before Run(CancellationToken).