My game freezes whenever i use any fucntion which includes any http calls. I mean the game is waiting for the data to get completed eveything else stops in the mean time. Like the sprite animations,game time,etc..
Example:
public PendingGamesByUser GetPendingGamesByUser(string userName)
{
XmlNode xmlNodes = null;
PendingGamesByUser pendingGamesByUser = new PendingGamesByUser();
List pendingGamesYourTurns = new List();
List pendingGamesTheirTurns = new List();
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(string.Concat("http://www.poquere.com/gotchha/getPendingGames.php?name=", userName));
HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
string end = (new StreamReader(response.GetResponseStream())).ReadToEnd();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(end);
string empty = string.Empty;
foreach (XmlNode xmlNodes in xmlDocument.SelectNodes("//response/data/yourturn"))
{
empty = xmlNodes.InnerText;
PendingGamesYourTurn pendingGamesYourTurn = new PendingGamesYourTurn();
pendingGamesYourTurns.Add(JsonConvert.DeserializeObject(empty));
}
foreach (XmlNode xmlNodes1 in xmlDocument.SelectNodes("//response/data/theirturn"))
{
empty = xmlNodes1.InnerText;
PendingGamesTheirTurn pendingGamesTheirTurn = new PendingGamesTheirTurn();
pendingGamesTheirTurns.Add(JsonConvert.DeserializeObject(empty));
}
pendingGamesByUser.PendingYourTurn = pendingGamesYourTurns.ToArray();
pendingGamesByUser.PendingTheirTurn = pendingGamesTheirTurns.ToArray();
return pendingGamesByUser;
}
When i call the above function like below
pendinggame = GetPendingGamesByUser("kannan21jan");
it lags right there. How to solve this?
↧