views:

121

answers:

1

I'm using C# .NET 4 and MSSQL.

I'm writing a code that downloads the html of different websites and analyses it using Regex.

Most of the time it takes the code to execute is waiting for the website html download to finish.

Currently i'm using Task.Factory.StartNew to create multiple threads that call DownloadHtml() . DownloadHtml uses WebRequest & StreamReader to download and read the website's html.

1.Should i change the DownloadHtml to use Async WebRequest and just use a single thread ? 2.How is this different from using multiple threads?

A: 
  1. I would recommend that you do use the async web request. It is important to know that this does not use a single thread. The callback for the async request will execute on a threadpool background thread. As you are using the TPL I would suggest you look at the functionality build into these classes to support async requests (http://msdn.microsoft.com/en-us/library/dd997423.aspx).

  2. As mentioned this does use multiple threads still.

btlog
thx , so why is async WebRequest better than using Task.Factory.StartNew ?
sharru