-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
AsyncCommnad not Cancelable
appLifetime.ApplicationStopping will never stop even if called by an other background service or strg+c. (return 99 in my example)
I didn't found a solution right now, do you have some suggestion ?
public class MyAsyncCommand : AsyncCommand<MyAsyncCommand.Settings>
{
private readonly DependencyService dependencyService;
private readonly IHostApplicationLifetime appLifetime;
public MyAsyncCommand(DependencyService service, IHostApplicationLifetime appLifetime)
{
this.dependencyService = service;
this.appLifetime = appLifetime;
}
public class Settings : CommandSettings
{
[Description("The shell commandline command")]
[CommandArgument(0, "<CommandName>")]
public string? CommandName { get; init; }
}
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
{
dependencyService.PerformAction();
try
{
await Task.Delay(20000, appLifetime.ApplicationStopping);
}
catch (Exception ex)
{
return 99;
}
return 1;
}
}
public class DependencyService
{
public void PerformAction()
{
Console.WriteLine("Action performed.");
AnsiConsole.Write(new Markup("[bold yellow]Hello[/] [red]World![/]"));
}
}
}
```
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels