I am trying to parse some pois from a xml download from a server and I saw that it is done after the program continues in the main thread. I haven't found a way to solve it because I need it.
using System.Threading; namespace XML_Parser { class XMLParserPOI_Wiki { private static XMLParserPOI_Wiki objSingle = new XMLParserPOI_Wiki(); public static XMLParserPOI_Wiki ObjSingle { get { return objSingle; } set { objSingle = value; } } private List<POI> places; public List<POI> Places { get { return places; } } private XMLParserPOI_Wiki() { } public void parseWikitude(string url) { places = new List<POI>(); WebClient wc = new WebClient(); wc.DownloadStringCompleted += HttpsCompleted; wc.DownloadStringAsync(new Uri(url)); } private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None); XNamespace ns = "http://www.opengis.net/kml/2.2"; XNamespace ns2 = "http://www.openarml.org/wikitude/1.0"; var placemarkers = xdoc.Root.Descendants(ns + "Placemark"); places = (from query in xdoc.Root.Descendants(ns + "Placemark") select new POI ( ... )).ToList(); System.Diagnostics.Debug.WriteLine("Lista"); System.Diagnostics.Debug.WriteLine(places.Count); } } } } In my main class:
XMLParserPOI_Wiki parserXML = XMLParserPOI_Wiki.ObjSingle; parserXML.parseWikitude("http://myurl.php"); System.Diagnostics.Debug.WriteLine("Lista de pois"); System.Diagnostics.Debug.WriteLine(parserXML.Places.Count); for (int i = 0; i < parserXML.Places.Count; i++) { System.Diagnostics.Debug.WriteLine(parserXML.Places[i].getName()); } It prints Lista de POis and 0, before Lista and X (number of pois)
I guess I should freeze main thread but I tried a couple of times with some examples and they didn't work.
Can you point me to any tutorial about this? More than get an answer I want to understand how to deal with this kind of operations