I am facing some processing speed issues with my wp8 app.
I have some questions and answers in my post call. I tried with whole question and just ID but it is processed in same time.
if (ansNo.Visibility == Visibility.Visible || ansYes.Visibility == Visibility.Visible)
{
if (ansNo.IsChecked == true || ansYes.IsChecked == true)
{
string token = Globals.token;
int counter = Globals.counter;
Globals.counter = Globals.counter + 1;
quizStatus.Text = "";
if (ansNo.IsChecked == true)
{
values.Add(new KeyValuePair<string, string>(quesId.Text, "f"));
}
else
{
values.Add(new KeyValuePair<string, string>(quesId.Text, "t"));
}
getQuiz(token, Globals.counter);
ansYes.IsChecked = false;
ansNo.IsChecked = false;
}
else
{
quizStatus.Text = "Please Select An Answer";
}
}
else
{
calculateType(values);
}
getquiz
gets the next question and quesId
holds the id for question and calculatetype
is the function where I am facing issues.
Here is calculatetype
:
public async Task calculateType(List<KeyValuePair<string, string>> values)
{
//quizText.Text = values.ToString();
quizText.Text = "Calculating Type...";
nextButton.Visibility = Visibility.Collapsed;
var httpClient = new HttpClient(new HttpClientHandler());
HttpResponseMessage response = await httpClient.PostAsync("http://107.170.34.31:3000/calculateusertype", new FormUrlEncodedContent(values));
response.EnsureSuccessStatusCode();
var typeResponse = await response.Content.ReadAsStringAsync();
JToken r = JToken.Parse(typeResponse);
userResult.Visibility = Visibility.Visible;
ansYes.Visibility = Visibility.Collapsed;
ansNo.Visibility = Visibility.Collapsed;
ContentPanel.Visibility = Visibility.Collapsed;
userType.Text = r["type"].ToString();
}
here is my getquestion function
public async Task getQuiz(String token,int counter)
{
if (counter > 0)
{
JToken p = JToken.Parse(Globals.responseString);
int arryCount = p["questions"].Count() - 1;
if (counter <= arryCount)
{
//quizText.Text = p["questions"][counter]["_id"].ToString();
quizText.Text = p["questions"][counter]["question"].ToString();
quesId.Text = p["questions"][counter]["_id"].ToString();
}
else
{
quizText.Text = "You Have Completed The Test. Click Next to Get Your Type.";
ansYes.Visibility = Visibility.Collapsed;
ansNo.Visibility = Visibility.Collapsed;
}
}
else
{
var values = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("token", token)
};
var httpClient = new HttpClient(new HttpClientHandler());
HttpResponseMessage response = await httpClient.PostAsync("http://107.170.34.31:3000/quiz", new FormUrlEncodedContent(values));
response.EnsureSuccessStatusCode();
Globals.responseString = await response.Content.ReadAsStringAsync();
JToken o = JToken.Parse(Globals.responseString);
Globals.quizcount = o["questions"].Count();
Globals.answers = new string[Globals.quizcount];
//o = JObject.Parse(responseString);
if (Globals.responseString != "")
{
//quizText.Text = o["questions"][counter]["_id"].ToString();
quizText.Text = o["questions"][counter]["question"].ToString();
quesId.Text = o["questions"][counter]["_id"].ToString();
}
}
}
Any suggestions to make this faster?