jty202 wrote:
OK specifically, I have a list of webpages I want to retrieve and
parse for information.
I want to allow the user to select which sites to retrieve and parse.
When the user enters the selection, I want to spawn a thread to
retreeve and parse for each webpage. After each thread have finish
parsing the data, it puts the extracted data in one common data
holder and the thread finishes. When all the threads finished, I want
to use the data holder to display the data in results page. So thats
the multithreading I want to do.
Create a new System.Net.HttpWebRequest for each page you want to fetch.
Assuming you're just doing GET (not POST) requests, all you need to do is
call BeginGetResponse on each request and it will be processed by a worker
thread from the ASP.NET I/O pool.
The worker threads will call your AsyncCallback as each request completes
and you can get the stream and read the response into whatever structure
suits your needs.
Your main thread (the one that initiated all the GETs) will need to block on
a suitable synchronization structure that becomes signalled when all the
async requests have completed (or optionally, wakes up each time a request
complete and blocks again if more requests are still in flight).
-cd