Very Slow WebResponse triggering TimeOut

Posted by David Fdez on Stack Overflow See other posts from Stack Overflow or by David Fdez
Published on 2009-07-06T21:45:13Z Indexed on 2010/04/10 4:03 UTC
Read the original article Hit count: 475

Filed under:
|
|
|

Hello:

I have a function in C# that fetches the status of Internet by retrieving a 64b XML from the router page

public bool isOn()
        {
            HttpWebRequest hwebRequest = (HttpWebRequest)WebRequest.Create("http://" + this.routerIp + "/top_conn.xml");
            hwebRequest.Timeout = 500;
            HttpWebResponse hWebResponse = (HttpWebResponse)hwebRequest.GetResponse();
            XmlTextReader oXmlReader = new XmlTextReader(hWebResponse.GetResponseStream());       
            string value;
            while (oXmlReader.Read())
            {
                value = oXmlReader.Value;
                if (value.Trim() != ""){
                    return !value.Substring(value.IndexOf("=") + 1, 1).Equals("0");
                }
            }
            return false;

        }

using Mozilla Firefox 3.5 & FireBug addon i guessed it normally takes 30ms to retrieve the page however at the very huge 500ms limit it stills reach it often. How can I dramatically improve the performance?

Thanks in advance

© Stack Overflow or respective owner

Related posts about c#

Related posts about httpwebrequest