469,917 Members | 1,644 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

HttpWebResponse seems to hang

Hello,

In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60000);
HttpWebRequest
wReq=(HttpWebRequest)WebRequest.Create("http://pipa.inov.pt/cgi-bin/camera");

HttpWebResponse wRes=(HttpWebResponse)wReq.GetResponse();
MessageBox.Show("Completed...");
}
}
The problem is: "It only completes 2 times...". Why doesn't it get
completed all the times I want... and why does it hangs (on the thread
of course) in GetResponse() method?

The strange thing is that when I try to access any of the wRes
properties it doesn't complete nothing at all. More: it doesn't give
any exceptions... nothing... it seems like the function evaporates to
nowhere.

Tried with different websites and all give the same problem... hangs up
at the 3rd time. I'm not seeing the complete message for the third time
in all types of webpages (static .html; .asp; etc...)

Thanks for any help,
Nuno Magalhaes.

Nov 17 '05 #1
3 4443
Nuno,

Just guessing, AFAIK does standard with http 1.1 a computer handles only 2
http requests in the same time. (AFAIK is this build in by the builders of
the operating systems, this is an agreement with Internet providers)

Cor
"Nuno Magalhaes" <nu************@hotmail.com> schreef in bericht
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello,

In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60000);
HttpWebRequest
wReq=(HttpWebRequest)WebRequest.Create("http://pipa.inov.pt/cgi-bin/camera");

HttpWebResponse wRes=(HttpWebResponse)wReq.GetResponse();
MessageBox.Show("Completed...");
}
}
The problem is: "It only completes 2 times...". Why doesn't it get
completed all the times I want... and why does it hangs (on the thread
of course) in GetResponse() method?

The strange thing is that when I try to access any of the wRes
properties it doesn't complete nothing at all. More: it doesn't give
any exceptions... nothing... it seems like the function evaporates to
nowhere.

Tried with different websites and all give the same problem... hangs up
at the 3rd time. I'm not seeing the complete message for the third time
in all types of webpages (static .html; .asp; etc...)

Thanks for any help,
Nuno Magalhaes.

Nov 17 '05 #2
Hi Nuno. Actually it does throw an exception, a System.Net.WebException
after 100 seconds (the default timeout for Web Responses).

It's being caused by not closing your resources. You need to close your
HttpWebResponse when you are done with it. Here is the modified code that
works.

HttpWebResponse wRes = null;

try
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60000);
HttpWebRequest wReq=(HttpWebRequest)
WebRequest.Create("http://pipa.inov.pt/cgi-bin/camera");

wRes =(HttpWebResponse)wReq.GetResponse();

MessageBox.Show("Completed...");

// Close the wRes object. Limited resources available.
wRes.Close();
wRes = null;
}
}
catch(System.Exception ex)
{
// Handle the exception appropriately
Debug.WriteLine(ex.ToString());
}
finally
{
// Clean up the resource in case it wasn't cleaned up previously.
if ( wRes != null )
wRes.Close();
}

Hope this helps.
- Jason Bartosch

"Nuno Magalhaes" wrote:
Hello,

In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60000);
HttpWebRequest
wReq=(HttpWebRequest)WebRequest.Create("http://pipa.inov.pt/cgi-bin/camera");

HttpWebResponse wRes=(HttpWebResponse)wReq.GetResponse();
MessageBox.Show("Completed...");
}
}
The problem is: "It only completes 2 times...". Why doesn't it get
completed all the times I want... and why does it hangs (on the thread
of course) in GetResponse() method?

The strange thing is that when I try to access any of the wRes
properties it doesn't complete nothing at all. More: it doesn't give
any exceptions... nothing... it seems like the function evaporates to
nowhere.

Tried with different websites and all give the same problem... hangs up
at the 3rd time. I'm not seeing the complete message for the third time
in all types of webpages (static .html; .asp; etc...)

Thanks for any help,
Nuno Magalhaes.

Nov 17 '05 #3
It actually helped. Thanks a lot.

Jason Bartosch wrote:
Hi Nuno. Actually it does throw an exception, a System.Net.WebException
after 100 seconds (the default timeout for Web Responses).

It's being caused by not closing your resources. You need to close your
HttpWebResponse when you are done with it. Here is the modified code that
works.

HttpWebResponse wRes = null;

try
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60000);
HttpWebRequest wReq=(HttpWebRequest)
WebRequest.Create("http://pipa.inov.pt/cgi-bin/camera");

wRes =(HttpWebResponse)wReq.GetResponse();

MessageBox.Show("Completed...");

// Close the wRes object. Limited resources available.
wRes.Close();
wRes = null;
}
}
catch(System.Exception ex)
{
// Handle the exception appropriately
Debug.WriteLine(ex.ToString());
}
finally
{
// Clean up the resource in case it wasn't cleaned up previously.
if ( wRes != null )
wRes.Close();
}

Hope this helps.
- Jason Bartosch

"Nuno Magalhaes" wrote:
Hello,

In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60000);
HttpWebRequest
wReq=(HttpWebRequest)WebRequest.Create("http://pipa.inov.pt/cgi-bin/camera");

HttpWebResponse wRes=(HttpWebResponse)wReq.GetResponse();
MessageBox.Show("Completed...");
}
}
The problem is: "It only completes 2 times...". Why doesn't it get
completed all the times I want... and why does it hangs (on the thread
of course) in GetResponse() method?

The strange thing is that when I try to access any of the wRes
properties it doesn't complete nothing at all. More: it doesn't give
any exceptions... nothing... it seems like the function evaporates to
nowhere.

Tried with different websites and all give the same problem... hangs up
at the 3rd time. I'm not seeing the complete message for the third time
in all types of webpages (static .html; .asp; etc...)

Thanks for any help,
Nuno Magalhaes.


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by hlabbott | last post: by
2 posts views Thread by Nuno Magalhaes | last post: by
4 posts views Thread by Dean Rettig | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.