Ejemplo n.º 1
0
        public MultiThreadedWebDownloader(string url, int bufferSize, int cacheSize,
                                          int bufferCountPerNotification, int maxThreadCount)
        {
            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "BufferSize cannot be less than 0. ");
            }

            if (cacheSize < bufferSize)
            {
                throw new ArgumentOutOfRangeException(
                          "MaxCacheSize cannot be less than BufferSize ");
            }

            if (bufferCountPerNotification <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "BufferCountPerNotification cannot be less than 0. ");
            }

            if (maxThreadCount < 1)
            {
                throw new ArgumentOutOfRangeException(
                          "maxThreadCount cannot be less than 1. ");
            }

            this.Url          = new Uri(url);
            this.BufferSize   = bufferSize;
            this.MaxCacheSize = cacheSize;
            this.BufferCountPerNotification = bufferCountPerNotification;

            this.MaxThreadCount = maxThreadCount;

            // Set the maximum number of concurrent connections allowed by
            // a ServicePoint object
            ServicePointManager.DefaultConnectionLimit = maxThreadCount;

            // Initialize the HttpDownloadClient list.
            downloadClients = new List <HttpDownloadClient>();

            // Set the idle status.
            this.status = MultiThreadedWebDownloaderStatus.Idle;
        }
        public MultiThreadedWebDownloader(string url, int bufferSize, int cacheSize,
                                          int bufferCountPerNotification, int maxThreadCount)
        {
            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "BufferSize 不能小于 0. ");
            }

            if (cacheSize < bufferSize)
            {
                throw new ArgumentOutOfRangeException(
                          "MaxCacheSize 不能小于 BufferSize ");
            }

            if (bufferCountPerNotification <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "BufferCountPerNotification不能小于 0. ");
            }

            if (maxThreadCount < 1)
            {
                throw new ArgumentOutOfRangeException(
                          "maxThreadCount 不能小于 1. ");
            }

            this.Url          = new Uri(url);
            this.BufferSize   = bufferSize;
            this.MaxCacheSize = cacheSize;
            this.BufferCountPerNotification = bufferCountPerNotification;

            this.MaxThreadCount = maxThreadCount;

            //设置最大连接数(被ServicePoint允许的范围下)
            ServicePointManager.DefaultConnectionLimit = maxThreadCount;

            //初始化HttpDownloadClient。
            downloadClients = new List <HttpDownloadClient>();

            // 设置闲置状态。
            this.status = MultiThreadedWebDownloaderStatus.Idle;
        }
        public MultiThreadedWebDownloader(string url, int bufferSize, int cacheSize,
            int bufferCountPerNotification, int maxThreadCount)
        {
            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(
                    "BufferSize 不能小于 0. ");
            }

            if (cacheSize < bufferSize)
            {
                throw new ArgumentOutOfRangeException(
                    "MaxCacheSize 不能小于 BufferSize ");
            }

            if (bufferCountPerNotification <= 0)
            {
                throw new ArgumentOutOfRangeException(
                    "BufferCountPerNotification不能小于 0. ");
            }

            if (maxThreadCount < 1)
            {
                throw new ArgumentOutOfRangeException(
                       "maxThreadCount 不能小于 1. ");
            }

            this.Url = new Uri(url);
            this.BufferSize = bufferSize;
            this.MaxCacheSize = cacheSize;
            this.BufferCountPerNotification = bufferCountPerNotification;

            this.MaxThreadCount = maxThreadCount;

            //设置最大连接数(被ServicePoint允许的范围下)
            ServicePointManager.DefaultConnectionLimit = maxThreadCount;

            //初始化HttpDownloadClient。
            downloadClients = new List<HttpDownloadClient>();

            // 设置闲置状态。
            this.status = MultiThreadedWebDownloaderStatus.Idle;
        }
        public MultiThreadedWebDownloader(string url, int bufferSize, int cacheSize,
            int bufferCountPerNotification, int maxThreadCount)
        {

            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(
                    "BufferSize cannot be less than 0. ");
            }

            if (cacheSize < bufferSize)
            {
                throw new ArgumentOutOfRangeException(
                    "MaxCacheSize cannot be less than BufferSize ");
            }

            if (bufferCountPerNotification <= 0)
            {
                throw new ArgumentOutOfRangeException(
                    "BufferCountPerNotification cannot be less than 0. ");
            }

            if (maxThreadCount < 1)
            {
                throw new ArgumentOutOfRangeException(
                       "maxThreadCount cannot be less than 1. ");
            }

            this.Url = new Uri(url);
            this.BufferSize = bufferSize;
            this.MaxCacheSize = cacheSize;
            this.BufferCountPerNotification = bufferCountPerNotification;
            
            this.MaxThreadCount = maxThreadCount;
            
            // Set the maximum number of concurrent connections allowed by 
            // a ServicePoint object
            ServicePointManager.DefaultConnectionLimit = maxThreadCount;

            // Initialize the HttpDownloadClient list.
            downloadClients = new List<HttpDownloadClient>();

            // Set the idle status.
            this.status = MultiThreadedWebDownloaderStatus.Idle;
        }