views:

34

answers:

2

I have an application that downloading urls using threadPool in different threads, but recently I've read an article (http://www.codeproject.com/KB/IP/Crawler.aspx) that it says HttpWebRequest.GetResponse() is working only in one thread and the other threads is waiting for that thread. first I want to know is it true ? how can i monitor which one of my threads is actually downloading with its status ?

+1  A: 

I doubt that HttpWebRequest.GetResponse would block other threads - but you can verify that easily using tools such as Fiddler. You can launch fiddler and run your program. The request would appear in Fiddler as soon as your program makes it and you can quickly determine if they are simultaneous or one by one.

VinayC
Yes your comment on instcode answer is exactly what I need to know, I'm running Fiddler but how can i be certain about that, cause fiddler does not show which request is running in the instance of time
Ehsan
I believe that your downloads will take at least few seconds - as such you should see multiple simultaneous requests in fiddler proving that parallel requests are possible. In Fiddler, statistics tab will tell you start time and end time of your request while time line tab can show you combined time-line for multiple requests (sessions as called by fiddler) - select multiple download requests and see time line tab.
VinayC
+1  A: 

Yes, GetResponse is a blocking call (check MSDN) which can only return when the server replies or a request timeout occurs. After that, just check the status code and use GetResponseStream to start downloading the returning content. Like this:

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == 200)
{
    Stream content = response.GetResponseStream();
    // Read the content and report the downloading progress...
    ...
}
instcode
I don't think Ehsan is worried about if GetResponse blocks current thread, he is concerned that it would block GetResponse calls on other threads making parallel downloads impossible.
VinayC