(text/x-fossil-plain)
When a provider inherit from System.Data.Common.DbConnection, it should overwrites the OpenAsync method to provides a native implementation. Elsewhere, calling the OpenAsync method will be the same as calling the Open method.
/// <summary>
/// This is the asynchronous version of <see cref="M:System.Data.Common.DbConnection.Open"/>. Providers should override with an appropriate implementation. The cancellation token can optionally be honored.The default implementation invokes the synchronous <see cref="M:System.Data.Common.DbConnection.Open"/> call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by Open will be communicated via the returned Task Exception property.Do not invoke other methods and properties of the DbConnection object until the returned Task is complete.
/// </summary>
///
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
/// <param name="cancellationToken">The cancellation instruction.</param>
public virtual Task OpenAsync(CancellationToken cancellationToken)
{
TaskCompletionSource<object> completionSource = new TaskCompletionSource<object>();
if (cancellationToken.IsCancellationRequested)
{
completionSource.SetCanceled();
}
else
{
try
{
this.Open();
completionSource.SetResult((object) null);
}
catch (Exception ex)
{
completionSource.SetException(ex);
}
}
return (Task) completionSource.Task;
}
|