Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When writing the below my code locks up on GetResponse. Why?

        try
        {
            WebRequest myWebRequest = WebRequest.Create(strURL);
            WebResponse myWebResponse = myWebRequest.GetResponse();
            //more code here
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
201 views
Welcome To Ask or Share your Answers For Others

1 Answer

This usually happens if you've made several requests to the same host, and not disposed of the WebResponse.

The default connection management settings only allow 2 (or maybe 4, I can't remember) open connections to the same host at a time. If you really need to change this, use the <connectionManagement> app.config element - but usually you'll be fine just disposing of WebResponse:

try
{
    WebRequest myWebRequest = WebRequest.Create(strURL);
    using (WebResponse myWebResponse = myWebRequest.GetResponse())
    {
        //more code here

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...