OpenRiaServices 异步方法

OpenRiaServices async methods

我仍在使用 OpenRiaServices,我更新到版本 5.0.0-preview0003。

我尝试添加一个异步方法:

[Invoke]
[RequiresAuthentication]
public async Task<string> GetTestAsync()
{
   return await Task.FromResult("TEST");
}

但是当我调用它时,该方法从不 returns :

var test = DomainContext.GetTestAsync(CancellationToken.None).Result;

我看到生成的代码中没有“等待”:

/// <summary>
/// Asynchronously invokes the 'GetTest' method of the DomainService.
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>An operation instance that can be used to manage the asynchronous request.</returns>
[DebuggerStepThrough()]
public System.Threading.Tasks.Task<InvokeResult<string>> GetTestAsync(CancellationToken cancellationToken = default(CancellationToken))
{
    this.ValidateMethod("GetTest", null);
    return this.InvokeOperationAsync<string>("GetTest", null, true, cancellationToken);
}

我试过调试,但我不知道问题出在哪里...

知道为什么吗?

问题已在 [OpenRiaServices Github)(https://github.com/OpenRIAServices/OpenRiaServices/issues/246)

上得到解答

问题是由于调用 Task.Result 而不是 await 结果

导致的死锁