title: Async XML Reading in Windows Phone 7
body: <p>So I have a Win Phone app that is finding a list of taxi companies and pulling their name and address from Bing successfully and populating a listbox that is being displayed to users. Now what I want to do is, to search for each of these terms on Bing, find the number of hits each search term returns and rank them accordingly (a loose sort of popularity ranking)</p>
  
  <pre><code>    void findBestResult(object sender, DownloadStringCompletedEventArgs e)
      {
              string s = e.Result;
              XmlReader reader = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(s)));
              String name = "";
              String rName = "";
              String phone = "";
              List&lt;TaxiCompany&gt; taxiCoList = new List&lt;TaxiCompany&gt;();
  
              while (reader.Read())
              {
                  if (reader.NodeType == XmlNodeType.Element)
                  {
                      if (reader.Name.Equals("pho:Title"))
                      {
                          name = reader.ReadInnerXml();
                          rName = name.Replace("&amp;amp;","&amp;");
                      }
  
                      if (reader.Name.Equals("pho:PhoneNumber"))
                      {
                          phone = reader.ReadInnerXml();
                      }
  
                      if (phone != "")
                      {
                          string baseURL = "http://api.search.live.net/xml.aspx?Appid=&lt;MyAppID&gt;&amp;query=%22" + name + "%22&amp;sources=web";
                         WebClient c = new WebClient();
                          c.DownloadStringAsync(new Uri(baseURL));
                          c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(findTotalResults);
                          taxiCoList.Add (new TaxiCompany(rName, phone, gResults));
                      }
                      phone = "";
                      gResults ="";
                  }
              TaxiCompanyDisplayList.ItemsSource = taxiCoList;
          }
      }
  </code></pre>
  
  <p>So that bit of code finds the taxi company and launches an asynchronous task to find the number of search results ( gResults ) to create each teaxicompany object. </p>
  
  <pre><code>    //Parses search XML result to find number of results
      void findTotalResults(object sender, DownloadStringCompletedEventArgs e)
      {
          lock (this)
          {
              string s = e.Result;
              XmlReader reader = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(s)));
              while (reader.Read())
              {
                  if (reader.NodeType == XmlNodeType.Element)
                  {
                      if (reader.Name.Equals("web:Total"))
                      {
                          gResults = reader.ReadInnerXml();
                      }
  
                  }
              }
          }
      }
  </code></pre>
  
  <p>The above snipped finds the number of search results on bing, but the problem is since it launches async there is no way to correlate the gResults obtained in the 2nd method with the right company in method 1. Is there any way to either:</p>
  
  <p>1.) Pass the name and phone variables into the 2nd method to create the taxi object there</p>
  
  <p>2.) Pass back the gResults variable and only then create the corresponding taxicompany object?</p>