Skip to content

Cancellation

Stanislav Molchanovskiy edited this page Nov 30, 2021 · 3 revisions

To cancel the request, you should pass a cancellation token to the method. The token must be the last parameter and must not have attributes:

public interface IMyClient
{
    [GetMethod] 
    Task<Entity> GetAsync(int id, CancellationToken cancellationToken);
}

...

var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(3500);
var entity = await myClient.GetAsync(id: 1, cancellationTokenSource.Token);

Clone this wiki locally