我有一个多层.Net 4.5应用程序调用一个方法使用C#的新async
和await
关键字挂起,我不明白为什么.
在底部我有一个异步方法来扩展我们的数据库实用程序OurDBConn
(基本上是底层DBConnection
和DBCommand
对象的包装器):
public static async Task<T> ExecuteAsync<T>(this OurDBConn dataSource, Func<OurDBConn, T> function)
{
string connectionString = dataSource.ConnectionString;
// Start the SQL and pass back to the caller until finished
T result = await Task.Run(
() =>
{
// Copy the SQL connection so that we don't get two commands running at the same time on the same open connection
using (var ds = new OurDBConn(connectionString))
{
return function(ds);
} …
Run Code Online (Sandbox Code Playgroud)