title: How do I check if WebClient download is completed before I execute a function?
body: <p>I am trying to get to JSON files from different URLs.  How do I make sure both files are downloaded completely before I try to execute something else.  </p>
  
  <p>My code looks something like this:</p>
  
  <pre><code>WebClient Url1 = new WebClient();
  Url1.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Url1_DownloadStringCompleted);
  Url1.DownloadStringAsync(new Uri("http://example.com"));
  WebClient Url2 = new WebClient();
  Url2.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Url2_DownloadStringCompleted);
  Url2.DownloadStringAsync(new Uri("http://anotherexample.com"));
  
  DoSomethingWithJson();
  
  void Url1_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  {
      if (e.Error != null) 
          return;
      json1 = JObject.Parse(e.Result);
  }
  
  void Url2_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  {
      if (e.Error != null) 
          return;
      json2 = JObject.Parse(e.Result);
  }
  </code></pre>
  
  <p>Right now, what happens is json1 and json2 returns null values whenever I try to display them in a MessageBox inside DoSomethingWithJson(), and I am assuming this might be because they haven't been downloaded completely.</p>