How to Resolve "The operation has timed out" error

45,587

How long is it before the request times out? Are you able to navigate to the url from a web browser?

Set HttpWebRequest.ReadWriteTimeout property on HttpWebRequest to a much higher value than what it is currently. The default value is 5 minutes. Not sure why it should take more than 5 minutes.

Instead of blocking on the getresponse, you could as well use async callbacks (BeginGetResponse/EndGetResponse).

EDIT

<system.diagnostics>
  <trace autoflush="true" />
  <sources>
    <source name="System.Net">
      <listeners>
        <add name="System.Net"/>
      </listeners>
    </source>
    <source name="System.Net.HttpListener">
      <listeners>
        <add name="System.Net"/>
      </listeners>
    </source>
    <source name="System.Net.Sockets">
      <listeners>
        <add name="System.Net"/>
      </listeners>
    </source>
    <source name="System.Net.Cache">
      <listeners>
        <add name="System.Net"/>
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add
      name="System.Net"
      type="System.Diagnostics.TextWriterTraceListener"
      initializeData="trace.log"
      traceOutputOptions = "ProcessId, DateTime"
            />
  </sharedListeners>
  <switches>
    <add name="System.Net"
         value="Verbose" />
    <add name="System.Net.Sockets"
         value="Verbose" />
    <add name="System.Net.Cache"
         value="Verbose" />
    <add name="System.Net.HttpListener"
         value="Verbose" />
  </switches>
</system.diagnostics>  

Add this section inside configuration section in the app.config of your application. After adding the above, rebuild the solution and run it. Look at the trace.log written in the bin directory of your application for more details.

Share:
45,587
Victor Athoti.
Author by

Victor Athoti.

Updated on July 09, 2022

Comments

  • Victor Athoti.
    Victor Athoti. almost 2 years

    I have a problem that while downloading the data it shows the error "The Operation has timed out".

    What can i do to resolve this error? I am using Win forms(C#) here is my code please check it and give suggestions. Where should i change the code please help me...

      public void ProcessData()
            {
    
    
                try
                {
                string MessageTitle = "";
                int pages = Convert.ToInt32(txtPages.Text);
    
                for (int k = Count; k <= pages; k++)
                {
    
                    string url = "http://www.yellowpages.com/" +StateName.ToLower()+ "/" + CategoryName + "?g=" + StateName + "&page=" + k + "&q=" + CategoryName + "";//txtYP.Text + k;
                    System.Net.HttpWebRequest httpRequest;
                    System.Net.HttpWebResponse httpResponse;
                    System.IO.StreamReader SReader;
                    string html;
                    httpRequest = (System.Net.HttpWebRequest)(System.Net.HttpWebRequest.Create(url));
                    httpRequest.Method = "GET";
                    httpResponse = (System.Net.HttpWebResponse)(httpRequest.GetResponse());
                    SReader = new StreamReader(httpResponse.GetResponseStream());
                    html = SReader.ReadToEnd();
                    string strDummy = html;
                    httpResponse.Close();