-
Notifications
You must be signed in to change notification settings - Fork 415
Description
If you use a command handler that is cancellable:
CommandHandler.Create<IConsole, CancellationToken>(async (console, cancellationToken) =>
{
while (true)
{
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
console.Out.WriteLine("Still alive");
}
}There's a good chance in general that it will cancel by throwing TaskCanceledException or OperationCanceledException, since the TPL is designed around throwing these. System.Threading.Tasks.Task goes so far as to recognize these exceptions as cancellation rather than failure.
However, System.CommandLine treats it as though it was like any other exception. That causes this unpleasantness when the user presses Ctrl+C.
This exception should never be unhandled so long as the cancellation token has actually been set, since System.CommandLine should be expecting it.
(OperationCanceledException.CancellationToken should be ignored because there are plenty of APIs that lose the cancellation token by having to use TaskCompletionSource.SetCanceled or CancellationTokenSource.CreateLinkedTokenSource in their implementation.)
