title: c# .net 4.5 async / multithread?
body: <p>I'm writing a C# console application that scrapes data from web pages.</p>
  
  <p>This application will go to about 8000 web pages and scrape data(same format of data on each page).</p>
  
  <p>I have it working right now with no async methods and no multithreading.</p>
  
  <p>However, I need it to be faster. It only uses about 3%-6% of the CPU, I think because it spends the time waiting to download the html.(WebClient.DownloadString(url))</p>
  
  <p>This is the basic flow of my program</p>
  
  <pre><code>DataSet alldata;
  
  foreach(var url in the8000urls)
  {
      // ScrapeData downloads the html from the url with WebClient.DownloadString
      // and scrapes the data into several datatables which it returns as a dataset.
      DataSet dataForOnePage = ScrapeData(url);
  
      //merge each table in dataForOnePage into allData
  }
  
  // PushAllDataToSql(alldata);
  </code></pre>
  
  <p>Ive been trying to multi thread this but am not sure how to properly get started. I'm using .net 4.5 and my understanding is async and await in 4.5 are made to make this much easier to program but I'm still a little lost.</p>
  
  <p>My idea was to just keep making new threads that are async for this line</p>
  
  <pre><code>DataSet dataForOnePage = ScrapeData(url);
  </code></pre>
  
  <p>and then as each one finishes, run</p>
  
  <pre><code>//merge each table in dataForOnePage into allData
  </code></pre>
  
  <p>Can anyone point me in the right direction on how to make that line async in .net 4.5 c# and then have my merge method run on complete?</p>
  
  <p>Thank you.</p>
  
  <p>Edit: Here is my ScrapeData method:</p>
  
  <pre><code>public static DataSet GetProperyData(CookieAwareWebClient webClient, string pageid)
  {
      var dsPageData = new DataSet();
  
      // DOWNLOAD HTML FOR THE REO PAGE AND LOAD IT INTO AN HTMLDOCUMENT
      string url = @"https://domain.com?&amp;id=" + pageid + @"restofurl";
      string html = webClient.DownloadString(url);
      var doc = new HtmlDocument();
      doc.LoadHtml(html );
  
      // A BUNCH OF PARSING WITH HTMLAGILITY AND STORING IN dsPageData 
      return dsPageData ;
  }
  </code></pre>