If I am making a library for my team that will be shared between multiple projects and the library is doing work that lends itself to be a good candidate for async/await
, should I also include non-async/await versions of the code? It seems like a lot of duplicate code, but I don't see any alternative. Is this just the price you pay for having the ability to have increased thread pool utilization?
Just to be clear, I am not asking if I should include a synchronous wrapper method, which is all I have been able to find answers to.
For example, I might have a long running SQL query. I would then need to implement this interface with two methods that are almost identical, one using the async
methods on SqlConnection
and SqlCommand
, and one not using them. Is this the correct approach or am I missing something?
public interface ILongRunningOperation
{
Response LongRunningOperation();
Task<Response> LongRunningOperationAsync();
}
Thanks!