【发布时间】:2017-07-08 13:20:29
【问题描述】:
我正在尝试在 xamarin Studio (c#) 中执行异步任务,但我缺少关于 async/await 的一些内容。这是我的代码。它永远不会完成这个功能。
public static async Task<string> AsyncTask()
{
using (var client = new HttpClient())
{
var values = new Dictionary<string, string>
{
{ "thing1", "this is the second time" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(DATA_SOURCE, content);
var responseString = await response.Content.ReadAsStringAsync();
System.Diagnostics.Debug.WriteLine("PART 2:" + responseString);
_json = responseString;
return _json;
}
}
【问题讨论】:
-
显示调用上述函数的代码。在堆栈更高的地方有一个阻塞调用,例如“
.Result或.Wait”,检查它们是否存在。
标签: xamarin async-await