Mudassir Hasan
Mudassir Hasan

Reputation: 28761

Operation timed out error when downloading with WebClient

I am getting Operation timed out exception .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;

namespace Timer1
{
    class Program
    {
        static void Main(string[] args)
        {

            Timer t = new Timer(TimerCallback, null, 0, 420000); // 7 minutes

        }
        private static void TimerCallback(Object o)
        {


            string url = string.Empty;
            WebClient client = new WebClient();
            url = @"http://myurl.com";
            client.DownloadString(url);


        }
    }
}

Is there a way to increase timeout property ? Please help.

Upvotes: 1

Views: 4794

Answers (1)

Gonzalo
Gonzalo

Reputation: 21175

The simplest answer is to use client.Timeout = 420000 (WebRequest.Timeout), but if you are going to do that with a timer, you might as well try an asynchronous version. Something along the lines of Set timeout for webClient.DownloadFile()

Upvotes: 5

Related Questions