【问题标题】:How i can cancel a ExecuteReaderAsync with CancellationToken我如何使用 CancellationToken 取消 ExecuteReaderAsync
【发布时间】:2016-12-27 01:18:31
【问题描述】:

我有一个长时间运行的查询,当我尝试使用 CancellationToken 中止查询时,没有任何反应。

using (var cmd = connection.CreateCommand())
{
    cmd.CommandText = contrat.StoredProcedureName;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandTimeout = 2000;
    AddParameters(cmd, contrat.ParametresCommand);

    using (var reader = await cmd.ExecuteReaderAsync(Token))
    {
        return contrat.ConvertAsync(reader);
    }    
}                    

【问题讨论】:

    标签: c# sql-server cancellationtokensource cancellation-token


    【解决方案1】:

    您需要在令牌上设置超时值,或者手动取消令牌。

    【讨论】:

    • 我已经取消了我的令牌,它在客户端被取消,但在服务器端没有被取消
    猜你喜欢
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-03
    • 1970-01-01
    • 1970-01-01
    • 2018-06-06
    相关资源
    最近更新 更多