title: How do I deal with this windows phone webclient asynchronous issue?
body: <p>I have a method as follows:</p>
  
  <pre><code>      public decimal GetExchangeRate(string fromCurrency, string toCurrency)
        {
              GoogleCurrencyService googleCurrencyService = new GoogleCurrencyService();
              return googleCurrencyService.GetRateForCurrency(fromCurrency, toCurrency);
  
        } 
  </code></pre>
  
  <p>and another class as follows</p>
  
  <pre><code>public class GoogleCurrencyService
  {
      public decimal GetRateForCurrency(string fromCurrency, string toCurrency)
      {
  
          try
          {
              WebClient client = new WebClient();
              client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(StringDownloadCompleted);
              client.DownloadStringAsync(new Uri(_requestUri + fromCurrency + "=?" + toCurrency));
  
          }
          catch (Exception)
          {
              ExchangeRate = 0;
          }
  
          return ExchangeRate;
      }
  
      private void StringDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
      {
          _response = e.Result;
          ExchangeRate = ParseResponseAndGetExchangeRate();
      }
  
  }//class GoogleCurrencyService
  </code></pre>
  
  <p>the variable ExchangeRate always come out as zero, so I believe the function call "GetRateForCurrency" returns before the async callback gets called. How do I make sure that does not happen as I need the variable ExchangeRate  to be set before being returned. Thanks. Also, I have noticed that the callback never gets called as I have a breakpoint in it and the exception as well which does not get called. So I donot know where the problem is.Any help appreciated.</p>