473,890 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# WebResponse Problem

4 New Member
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 2341
Plater
7,872 Recognized Expert Expert
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
KyleUbenk
4 New Member
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 Recognized Expert Expert
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
1485
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 an FTP server. I used the following code WebRequest req = WebRequest.Create (url); req.Credentials = new NetworkCredential (username, pass); WebResponse res = req.GetResponse();
6
6153
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 on a receive. at(System.Net.HttpWebRequest.CheckFinalStatus()) at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at(System.Net.HttpWebRequest.GetResponse())
2
1590
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 i want to remove memory allocated by this object. am using close method and after that i am setting it to null. My pronlem is that at a time of setting webrequest to null sometimes it is taking more than 10 minutes. similary at a time of closing...
3
1650
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 one tell me how to do this. Any help will be appreciated. thanks in advance.
6
1643
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*: http://planetbrent.com/test.aspx?url=http://www.yahoo.com http://planetbrent.com/test.aspx?url=http://www.msn.com http://planetbrent.com/test.aspx?url=http://www.sec.gov http://planetbrent.com/test.aspx?url=http://sec.gov/Archives/edgar/data/1061165/000090266405001703/0000902664-05-001703.txt ...
2
3395
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 scenario - when the web browser requests a file, the IIS Server1 has to go back to Server2 to make a request for the file. Server2 then responds the file back to Server1 and Server1 should be able to just forward the file down to the web browser....
4
1912
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 to my target url and it will respond with a value depend on a value which i send. <SELECT name=langpair><OPTION value=en|de>English to German</OPTION><OPTION value=en|es>English to Spanish</OPTION> </select>
0
1508
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:- try {
4
2138
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 what is going on. I'm not getting any errors right now, but code is not working either - not reading the post in second form or else the first form is not sending it correctly....
0
9978
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10462
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8016
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6045
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4676
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.