相关疑难解决方法(0)

为什么这个异步操作会挂起?

我有一个多层.Net 4.5应用程序调用一个方法使用C#的新asyncawait关键字挂起,我不明白为什么.

在底部我有一个异步方法来扩展我们的数据库实用程序OurDBConn(基本上是底层DBConnectionDBCommand对象的包装器):

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)

c# asynchronous task-parallel-library async-await c#-5.0

96
推荐指数
4
解决办法
5万
查看次数