473,414 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

C# WebResponse Problem

Well I have a multi-threaded program which downloads URL sources from the web. Im doing this multiple times at once. The only problem I see is that sometimes it takes a while to download the source
Expand|Select|Wrap|Line Numbers
  1. WebResponse ServerResponse = webrequest.GetResponse();
and only one webresponse can happen at once because the rest of the threads seem to wait on the first webresponse to finish. Is there a way around this? I hope you understand what my problem is.

Expand|Select|Wrap|Line Numbers
  1. public static void run() {
  2.  
  3. string reply = "";
  4. string link = ("http://www.google.com");
  5. WebRequest webrequest = WebRequest.Create(link);
  6.  
  7.             try
  8.             {
  9.                 WebResponse ServerResponse = webrequest.GetResponse();
  10.                 StreamReader streamreader = new  StreamReader(ServerResponse.GetResponseStream());
  11.                 reply = streamreader.ReadToEnd();
  12.  
  13.                 ServerResponse.Close();
  14.                 streamreader.Close();
  15.             }
  16.             catch (Exception e)
  17.             {
  18.                 MessageBox.Show(e.Message);
  19.             }
  20. }
Nov 19 '07 #1
3 2323
Plater
7,872 Expert 4TB
I don't know why it would wait, unless you're using the same object/same thread.

Have you tried using the HttpWebRequest? It might provide better functionality for you.
Nov 19 '07 #2
I don't know why it would wait, unless you're using the same object/same thread.

Have you tried using the HttpWebRequest? It might provide better functionality for you.
Could it be something to do with the way im doing the threads? Im new to C# .
I'm starting the threads similar to this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Thread[] ThreadArray = new Thread[5];
  3.  
  4.                for (int i = 0; i < 5; i++)
  5.                 {
  6.                   ThreadArray[i] = new Thread(delegate() { runme(URL, timeout); });
  7.                   ThreadArray[i].Start();
  8.                 }
  9.  
Nov 19 '07 #3
Plater
7,872 Expert 4TB
Hmm, well that looks ok as far thread starting goes.
Nov 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: amine | last post by:
I really need help on this please. I am writing an application for an Ipaq and I am trying to enable the application to connect to a DAV server which can is basically an HTTP server that acts like...
6
by: Jonathan | last post by:
Calling the System.Net.WebResponse.GetResponse method (see code below) results in the following error: System.Net.WebException: The underlying connection was closed: An unexpected error occurred...
2
by: trialproduct2004 | last post by:
Hi all. i am having problem at a time of validatiang url. I am using webrequest and webresponse class to get content of particular url. My problem is after using webrequest and webresponse class...
3
by: trialproduct2004 | last post by:
hi all can some one tell me how to call dispose method of webresponse. I am currently using close method. But this is creating problem. So i want to use dispose method of webresponse. Can some...
6
by: Brent | last post by:
I'm having odd problems with the WebResponse class. Some servers are speedy, while others don't play along at all. Consider the following pages*: ...
2
by: Jeff G. | last post by:
Hello everyone, I have read through the newsgroups (thank God for 'em!) extensively looking for an example of how to pass a file (PDF) from a webresponse stream down to a web client. Here's the...
4
by: Savas Ates | last post by:
I have a vb.net web application. I want to post some variables to another web page and take some values back and process them. This is codes in my target url. I should post "langpair" cariable...
0
by: archana | last post by:
Hi all, I am facing very strange problem while using webrequest. What i am doing is i have one url which i want to validate. so i am using webrequest and webresponse. My code is as below:-...
4
by: CindyH | last post by:
Hi - hope someone can help with this - this code was working for a while in the 'real' code and then suddenly stopped - not sure what happen. I made two simple forms on localhost to try to test...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.