我正在使用Windows Phone應用程序。在執行以下函數時,執行以下函數: HttpResponseMessage response = await client.GetAsync(connection1).ConfigureAwait(false);
它跳過代碼的其餘部分,然後控制轉到父函數並執行其餘代碼並再次返回到此函數。如何解決這個問題?異步函數調用問題
public async void vehicleValidation()
{
//isValidVehicle = true;
var client = new System.Net.Http.HttpClient();
//string connection = "http://mymlcp.co.in/mlcpapp/get_slot.php?vehiclenumber=KL07BQ973";
string connection1 = string.Format("http://mymlcp.co.in/mlcpapp/?tag=GetIsValidUser&employeeId={0}&name={1}",txtVeh.Text,"abc");
HttpResponseMessage response = await client.GetAsync(connection1).ConfigureAwait(false);
//var response = await client.GetAsync(connection1);
// HttpResponseMessage response = client.GetAsync(connection1).Result;
var cont = await response.Content.ReadAsStringAsync();
var floorObj = Newtonsoft.Json.Linq.JObject.Parse(cont);
//var resp = await (new MLCPClient()).GetIsValidUser(txtVeh.Text, "xyz");
if (String.IsNullOrEmpty(floorObj["error"].ToString()) || floorObj["error"].ToString().Equals("true"))
{
isValidVehicle = false;
}
else
{
isValidVehicle = true;
}
}
注的最佳做法介紹的是*正是*你應該期待什麼異步方法。這是一點。 –
我不認爲你應該使用'ConfigureAwait(false)',因爲它引發了'同步'問題。 – Venky
@jonSkeet你能解釋一下嗎? –