You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Never mind, I'm sorry. Just my ignorance of tasks. Turns out when I return it as a task and call for .Wait() in the managing class I can pass the CancellationToken in there.
@rollemira be careful; Task.Wait(CancellationToken) will only cancel the wait, not the actual Command and underlying process.
If you want to actually abort the command via cancellation token, your best bet today is:
var command = Command.Run(...);
// when the token is canceled, abort the command
cancellationToken.Register(() => command.Kill());
// could pass the token in here, but that wouldn't add much since killing the process will also end the wait
// at that point, you'll either see an exception (if you set ThrowOnError(), or a successful return with an error exit code (the default)
command.Task.Wait();
That said, it would be nice if you could pass a CancellationToken in via options:
var command = Command.Run(
"somecommand",
new[] { "some", "arguments" },
options: o => o.CancellationToken(cancellationToken)
);
If we added this API, then a cancel would not only abort the process but would also cause Command.Task to change to the Canceled status.
I'm finding myself needing to give the constructed task created a cancellation token. If there is a way to do that, I'm just not finding it.
The text was updated successfully, but these errors were encountered: