Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Cancel async Ajax Request (CancellationToken)

$
0
0

Hello,

How to cancel a async Ajax Request?

I have the following Controller where I querying a database async and have the need to cancel it if it runs to Long...

  • Is it possible that using CancellationToken in ASP.NET Core is not possible?
  • How to cancel such a Operation from the Client?

public async System.Threading.Tasks.Task<ActionResult> ReadAsync([FromBody] JsonDict jsonDict, [DataSourceRequest] DataSourceRequest request, CancellationToken cancelToken)
        {
            try
            {
                var queryDict = jsonDict["query"] as JsonDict;
                var optionsDict = jsonDict["options"] as JsonDict;
                var query = eqService.GetQueryByJsonDict(queryDict);
                var sql = eqService.BuildQuery(query, optionsDict);

                var result = await Db.QueryAsync<dynamic>(sql, commandType: System.Data.CommandType.Text,cancellationToken: cancelToken);

                return Json(result.ToDataSourceResult(request));
            }
            catch (Exception ex)
            {
                return Json(ex);
            }

        }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>