mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
30 lines
695 B
C#
30 lines
695 B
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using CliFx.Attributes;
|
|
using CliFx.Infrastructure;
|
|
|
|
namespace CliFx.Tests.Dummy.Commands;
|
|
|
|
[Command("cancel-test")]
|
|
public class CancellationTestCommand : ICommand
|
|
{
|
|
public async ValueTask ExecuteAsync(IConsole console)
|
|
{
|
|
try
|
|
{
|
|
console.Output.WriteLine("Started.");
|
|
|
|
await Task.Delay(
|
|
TimeSpan.FromSeconds(3),
|
|
console.RegisterCancellationHandler()
|
|
);
|
|
|
|
console.Output.WriteLine("Completed.");
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
console.Output.WriteLine("Cancelled.");
|
|
throw;
|
|
}
|
|
}
|
|
} |