Jarloo

Menu

WebClient with Timeout Support

By default the C# WebClient class does not let you modify the default timeout value of 1 minute. This subclass exposes the Timeout property so you can change the default without having to use a HttpWebRequest.

using System;
using System.Net;

namespace Jarloo
{
    public class TimeoutWebClient : WebClient
    {
        public int Timeout { get; set; }

        public TimeoutWebClient()
        {
            Timeout = 60000;
        }

        public TimeoutWebClient(int timeout)
        {
            Timeout = timeout;
        }

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = base.GetWebRequest(address);
            request.Timeout = Timeout;
            return request;
        }
    }
}

Categories:   Code

Comments

  • Posted: October 5, 2013 02:19

    Omar

    Thank you, you're a life saver