I'm using MediatR in .Net core 3.1 Blazor application. The following are the query and its handler.
public class GetSaleQuery : IRequest<SaleVm>
{
public GetSaleQuery(string id)
{
Id = id;
}
public string Id { get; }
}
public class GetSaleQueryHandler : IRequestHandler<GetaQuery, SaleVm>
{
public async Task<SaleVm> Handle(GetSaleQuery request, CancellationToken cancellationToken)
{
var q = await _context.Table1
.ToListAsync(cancellationToken).ConfigureAwait(false);
return ...;
}
}
And in the UI part, the following is used to send query request.
async Task SearchClicked()
{
sendResult = await mediator.Send(new GetSaleQuery{ Id = id });
// page will use sendRest to display the result .....
}
Now I need to add a Cancel button to let user to cancel the long running query. How to pass the cancellation token to the query handler GetSaleQueryHandler.Handle()
?
async Task CancelButtonClicked()
{
// ?????
}