How can I inject or get access to the async cancellation token before executing a command? #2758
-
|
My console app already has termination handlers for ctrlc/break etc., I configure the environment before calling any command handlers, and I use a my cancellation token in async methods. Per the docs it looks like CLI configs its own ctrlc handler, and connects the async cancellation token to be signaled. This duplicates logic my app already manages, how can I e.g. prevent duplicate termination handling being created, pass in my own cancellation token to the CLI logic, reuse the CLI logic cancellation token, etc.? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
I wanted to disable System.CommandLine's handling of ctrl-c... and after hunting through the code wrote this: var parse = Cli.RootCommand.Parse(args);
parse.InvocationConfiguration.EnableDefaultExceptionHandler = false;
// Disable ^c (etc.) handling
parse.InvocationConfiguration.ProcessTerminationTimeout = null;
var canTok = SetupInterrupt();
return await parse.InvokeAsync(cancellationToken: canTok); |
Beta Was this translation helpful? Give feedback.
I wanted to disable System.CommandLine's handling of ctrl-c... and after hunting through the code wrote this: