【发布时间】:2016-12-19 14:33:26
【问题描述】:
我正在处理异步网络服务调用,并且正在玩这个任务并等待构造:
private static async Task<RSAParameters> GetPublicSecretKey(ICoreIdentityService identityChannel)
{
Object state = null;
var t = Task<RSAParameters>.Factory.FromAsync(
identityChannel.BeginGetPublicKey,
identityChannel.EndGetPublicKey,
null, state, TaskCreationOptions.None);
return await t;
}
//Methods definition:
//IAsyncResult BeginGetPublicKey(AsyncCallback callback, object asyncState)
//RSAParameters EndGetPublicKey(IAsyncResult result)
构建我得到的代码方法....的类型参数不能从使用中推断出来。我错过了什么吗?
提前致谢。干杯,inoel
修改后的编译代码:
var t = Task<RSAParameters>.Factory.FromAsync(
identityChannel.BeginGetPublicKey,
identityChannel.EndGetPublicKey,
TaskCreationOptions.None);
【问题讨论】:
-
我认为最简单的方法是
return await Factory.FromAsync... -
如果您只是要返回任务,则无需等待任务。就
return Factory.FromAsync
标签: c# macos asynchronous xamarin