HttpWebResponse doesn't always return

N

Nuno Magalhaes

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?

Any help is appreciated,
Nuno Magalhaes.
 
N

Nuno Magalhaes

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.

I'm lost. Please guide me to the holy light.
Thanks.
 
N

Nuno Magalhaes

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...)
 
J

Jon Skeet [C# MVP]

Nuno Magalhaes said:
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?

Any help is appreciated,

You're not disposing the response, so the framework is leaving the
connection open - and as it's only allowing two connections to the same
server to be open at a time, you've effectively got deadlock.

If you change your HttpWebResponse line to use a "using" statement, I
suspect you'll find it starts working fine.
 
G

Guest

Check your other post on the problem for the answer.

Hope it helps,
- Jason Bartosch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top