Using CancellationToken in ToDataSourceResultAsync to Stop Query
|Progress® Kendo UI® Grid for UI for ASP.NET MVC
How can I cancel the asynchronous call to database query or some other action if the time limit is reached or due to another problem?
ToDatasourceResultAsync method can be used to achieve asynchronous programming as demonstrated in this sample:
In real-life scenarios, developers usually have also to consider other factors like Connection Time Limit, Invalid Input, etc. To help with this task, we exposed the
CancellationToken parameter which comes handy in this type of scenarios:
public async Task<ActionResult> EditingInline_Read([DataSourceRequest] DataSourceRequest request)
CancellationTokenSource source = new CancellationTokenSource(2000);
CancellationToken token = source.Token;
var products = await productService.Read().ToDataSourceResultAsync(request, token);
This feature is available both for MVC and Core Telerik UI toolsets. A full runnable sample for ASP.NET Core can be found here:
For more information on asynchronous programming, see Microsoft's docs.