ASP.net multithreading?

J

jty202

Am I able to use ASP.net to multithread retrieve webpages?

Are there examples of using multithread in ASP.net?
 
P

Peter Bromberg [C# MVP]

This is a pretty vague question so it's a bit difficult to answer directly.
There is nothing to stop you from having an ASP.NET web page spawn separate
worker threads or to do asynchronous method processing using the underlying
..NET Threadpool.

However, without knowing exactly what it is you hope to accomplish, it would
be difficult to give more than the above "general" answer.

Provide some details, and get more detail in response.
Peter
 
J

jty202

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

Carl Daniel [VC++ MVP]

jty202 said:
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
 
C

Cor Ligthert

Jty

You got a nice and in my opinion very good answer from Carl, I want to warn
you for what you are doing. Carl wrote already that your mainthread is
dependend from all your worker threads. However in a websolution you have
normally not one client who is active, it will give you a lot of
synchronization in my opinion.

I would first try it without the multithreading.

Only trying to prevent you from the hole a lot went in.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top