Method Run
Run(CancellationToken)
Runs the input loop, continuously reading input and placing it into the queue provided by Initialize(ConcurrentQueue<TInputRecord>).
public void Run(CancellationToken runCancellationToken)
Parameters
runCancellationTokenCancellationTokenThe 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
runCancellationTokenor 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).