Is this a reasonable way to add async functionality to the IDbCommand interface?
public async static Task<IDataReader> ExecuteReaderAsync(this IDbCommand self) {
DbCommand dbCommand = self as DbCommand;
if (dbCommand != null) {
return await dbCommand.ExecuteReaderAsync().ContinueWith(task => (IDataReader)task.Result);
} else {
return await Task.Run(() => self.ExecuteReader());
}
}
Specifically, I'm not entirely sure what the effects of using "ContinueWith" to fake the covariance of "Task".
Also, in the unlikely case that the incoming "self" instance does not inherit from DbCommand, will a thread pool thread be consumed and blocked during the execution of "self.ExecuteReader()"?
Here's a link to my complete implementation of IDb extensions for async support.
Thank you
You are missing the
asyncandawaitif you are using .NET 4.5. The way you attempt is right and hope you are handling the connections separately.