How i can cancel a ExecuteReaderAsync with CancellationToken

624 views Asked by At

I have a long running query , when I try to abort the query with CancellationToken nothing happens.

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);
    }    
}                    
1

There are 1 answers

1
Brian Hayes On BEST ANSWER

You need to set a timeout value on the token, or manually cancel the token.