.NET 4 Async WebRequest vs. Multiple Threads

I am using C # .NET 4 and MSSQL.

I am writing code that loads HTML from different websites and parses it using Regex.

Most of the time it takes to execute the code, waiting for the HTML website to load.

I am currently using Task.Factory.StartNew to create multiple threads that call DownloadHtml (). DownloadHtml uses WebRequest & StreamReader to download and read the html website.

1. Should I change DownloadHtml to use Async WebRequest and use only one stream?
2. How is this different from using multiple threads?

+4
source share
1 answer
  • I would recommend you use async web request. It is important to know that this does not use a thread. The callback for the async request will be executed on the threadpool thread thread. Since you are using TPL, I would suggest that you study the functionality built into these classes to support asynchronous requests ( http://msdn.microsoft.com/en-us/library/dd997423.aspx ).

  • As already mentioned, this still uses multiple threads.

+1
source

All Articles