I need to do several HttpWebRequest requests in a single moment, but when I make the request several times will cost a lot of time. I plan on doing each request in a separate thread and then get all the returns and put it all together when all calls are completed is it possible?
Asked
Active
Viewed 86 times
0
-
Duplicate of: http://stackoverflow.com/questions/202481/how-to-use-httpwebrequest-net-asynchronously – hometoast Sep 28 '11 at 14:32
2 Answers
2
Absolutely.
Take a look at the msdn docs on HttpWebRequest.BeginGetResponse Method
I couldn't write a better example than in the docs.

hometoast
- 11,522
- 5
- 41
- 58
-
In this case, for each request made, will be called in a different thread? – mcamara Sep 28 '11 at 15:00
-
Right. You can kick off a bunch of threads, keep an array of ManualResetEvents, and then use WaitAll() to wait for all the web requests to finish. – hometoast Sep 28 '11 at 16:00
1
I don't know much about Threading, but as they run asynchronously, getting a return value isn't an option. However, this thread : http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/c43c0cce-491a-4ddb-9012-69929fab8e5e/ does point towards the ThreadPool class.

pikzen
- 1,413
- 1
- 10
- 18