Oracle.DataAccess.Client.OracleCommand ExecuteReaderAsync

时间:2013-10-25 19:30:53

标签: c# .net oracle task-parallel-library odp.net

因为OracleCommand类扩展了DbCommand类,所以它实现了它的Execute方法的Async版本。但是,我找不到任何对Oracle支持这些方法的OracleCommand类的引用(我使用的是11g): http://docs.oracle.com/html/E10927_01/OracleCommandClass.htm

有谁知道这是在做什么,以支持这些方法?它们似乎是非阻塞的并且在使用中支持取消(我希望NotImplementedException是诚实的),但由于文档的原因,我感觉不支持,所以我想确保没有任何陷阱。

1 个答案:

答案 0 :(得分:0)

Oracle客户端不会覆盖方法的异步版本。他们使用默认的DbCommand实现来调用方法的非异步版本。

例如,ExecuteNonQueryAsync的实现是:

// System.Data.Common.DbCommand
public virtual Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken)
{
    if (cancellationToken.IsCancellationRequested)
    {
        return ADP.CreatedTaskWithCancellation<int>();
    }
    CancellationTokenRegistration cancellationTokenRegistration = default(CancellationTokenRegistration);
    if (cancellationToken.CanBeCanceled)
    {
        cancellationTokenRegistration = cancellationToken.Register(new Action(this.CancelIgnoreFailure));
    }
    Task<int> result;
    try
    {
        result = Task.FromResult<int>(this.ExecuteNonQuery());
    }
    catch (Exception ex)
    {
        cancellationTokenRegistration.Dispose();
        result = ADP.CreatedTaskWithException<int>(ex);
    }
    return result;
}

正如您所看到的,它只是简单地调用ExecuteNonQueryExecuteNonQueryAsync的无参数重载调用此版本的方法)。