我想通过HttpClient进行异步调用以从RESTful WCF服务加载数据。该代码位于Xamarin UI中使用的可移植类库(PCL)中。看起来,异步调用从未被解雇。我已经阅读了关于这方面问题的博客,我相信我已经解决了这些问题。异步调用永不开启
我从做如下一个客户端的数据仓库类呼叫:
public MyRepository()
{
Task.Run(async() => { await LoadDataAsync(url); });
}
public async Task LoadDataAsync(string uri)
{
if (allRecords != null) **// Breakpoint here never hit.**
{
string responseJsonString = null;
using (var httpClient = new HttpClient())
{
try
{
Task<HttpResponseMessage> getResponse = httpClient.GetAsync(uri);
HttpResponseMessage response = await getResponse;
responseJsonString = await response.Content.ReadAsStringAsync();
myList = JsonConvert.DeserializeObject<List<MyListItem>>(responseJsonString);
}
catch (Exception ex)
{
}
}
}
}
任何帮助非常赞赏。提前致谢。
你真的不应该做一个空的catch(Exception ex)',你只是隐藏了很难诊断错误的错误。 –
你可以在桌面.NET上重现这一点吗? –