Send termination request #405
OskarKlintrot
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Regarding determining whether the process was cancelled or whether it timed out, this is the way to do it: var timeoutTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(2));
var terminationTokenSource = new CancellationTokenSource();
var combinedTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(timeoutTokenSource.Token, terminationTokenSource.Token);
var webApiTask = ReadAsync(
"dotnet",
"run",
workingDirectory: "path-to-my-api",
cancellationToken: combinedTokenSource.Token);
// Ping webapi
terminationTokenSource.Cancel();
try
{
var (output, error) = await webApiTask; // Not cancelled unless it has passed more than 2 minutes
}
catch (OperationCanceledException ex)) when (terminationTokenSource.IsCancellationRequested)
{
// the process was terminated
} However, this won't let you capture the output or error streams. While we could try and throw a custom exception, inheriting from Taking a step back for a moment, I think your use case may be a bit further advanced than the simple use cases SimpleExec is designed for. Perhaps you should look into using a more advanced package such as CliWrap. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I couldn't figure out a way to gracefully shutdown a dotnet app I'm testing. I wish I could send a termination request to let the process know that I want it to try to shut down and still be able to read the output from it. Something like this:
I can use the
cancellationToken
to at least kill the process and move on but I wish there were a way to still capture the output.Beta Was this translation helpful? Give feedback.
All reactions