473,799 Members | 3,782 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 2339
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
1482
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
6150
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
1588
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
1648
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
1640
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
3390
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
1910
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
1506
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
2132
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
9687
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
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
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
10237
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
10029
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...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
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
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.