4

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?

1
  • Generally Task.Factory.StartNew does not generate a new thread unless you pass it the LongRunningFlag. It creates a Task that will be scheduled on a thread (per default a thread pool thread). Commented Aug 24, 2010 at 11:12

1 Answer 1

1
  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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.