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
2010-08-17 10:49:51
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
2010-08-18 09:12:47
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
2010-08-18 09:23:34
+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
2010-08-17 12:00:55
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
2010-08-18 05:17:14