【发布时间】:2012-10-25 19:24:34
【问题描述】:
我有一些现有代码要移植到 Windows 8 WinRT。代码从 URL 获取数据,异步调用传递的委托:
private void RequestData(string uri, Action<string> action)
{
var client = new WebClient();
client.DownloadStringCompleted += (s,e) => action(e.Result);
client.DownloadStringAsync(new Uri(uri));
}
转换为 WinRT 需要使用 HttpClient 和异步方法。我已经阅读了一些关于 async / await 的教程,但有点困惑。如何更改上述方法,但保留方法签名以避免更改更多代码?
【问题讨论】:
标签: c# microsoft-metro async-await