Using thread in aspx-page making a webrequest?

There are issues you must consider when using multiple threads in ASP.NET.

There are issues you must consider when using multiple threads in ASP.NET. First of all, you have to realize that every ASP. NET page request arrives on a different worker thread.

There are already a lot of threads in use! Secondly, in your example, it seems that the page must wait for the response before returning HTML back to the browser. You won't save any time by using multiple threads, since the page still has to wait for the result.

The one benefit you might achieve comes from a combination of the above two issues. If your page is blocked waiting on the response from the web request, then that means you're holding up a worker thread while waiting for a response. That worker thread could instead be servicing another page request.

This can impact scalability. If scalability becomes a problem, you can use Asynchronous Pages to alleviate the problem in this case. With this model, when the page starts to wait on the web request, the page returns control back to ASP.NET.

The worker thread may then service another request. When the response from the web request arrives, the page can continue processing. In the meantime, your precious worker threads don't spend their time doing nothing.

See: Wicked Code: Asynchronous Pages in ASP. NET 2.0 Wicked Code: Scalable Apps and Asynchronous Programming in ASP.NET.

The advantage of doing this on a separate thread would be that your thread wouldn't block while the request is being retrieved. However, actually creating a thread and executing it is not recommended; you end up with a lot of synchronization problems--when is it done and how will you get the results etc. It is best to use an asynchronous method (which still uses another thread) as it allows you to simply specify a method to be called when the request has been retrieved. For HttpWebRequest.

GetResponse, the async method is HttpWebRequest. BeginGetResponse.

Great! Thank you. – Mike Ribeiro Jun 18 '10 at 4:53 I have to downvote since you didn't mention any of the issues specific to ASP.NET pages.

– John Saunders Jun 19 '10 at 21:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions