我的任务是从我的服务器获取内容。问题是,有时任务会覆盖之前的任务,所以我得到了两倍的结果。
我的代码:
Task<string> task = Server.GetText();
string result = await task;
if (result == "\n")
{
.....
}
else
{
string[] sarray = result.Split('|');
App.MainList.Add(new etc.Text(sarray[0], sarray[1], sarray[2], sarray[3], sarray[4]));
App.Number++;
}
获取文本():
public static async Task<string> GetText()
{
if (App.Number <= App.Total)
{
HttpClient http = new System.Net.Http.HttpClient();
HttpResponseMessage response = await http.GetAsync(queryuri + "?w=" + App.Number.ToString());
return await response.Content.ReadAsStringAsync();
}
else
{
App.Number = 1;
HttpClient http = new System.Net.Http.HttpClient();
HttpResponseMessage response = await http.GetAsync(queryuri + "?w=" + App.Number.ToString());
return await response.Content.ReadAsStringAsync();
}
}