/// <summary> /// Handle the DownloadProgressChanged event of all the HttpDownloadClients, and /// calculate the download speed. /// </summary> void client_DownloadProgressChanged(object sender, HttpDownloadClientProgressChangedEventArgs e) { lock (locker) { DownloadedSize += e.Size; bufferCount++; if (bufferCount == BufferCountPerNotification) { if (DownloadProgressChanged != null) { int speed = 0; DateTime current = DateTime.Now; TimeSpan interval = current - lastNotificationTime; if (interval.TotalSeconds < 60) { speed = (int)Math.Floor((this.DownloadedSize - this.lastNotificationDownloadedSize) / interval.TotalSeconds); } lastNotificationTime = current; lastNotificationDownloadedSize = this.DownloadedSize; var downloadProgressChangedEventArgs = new MultiThreadedWebDownloaderProgressChangedEventArgs( DownloadedSize, TotalSize, speed); this.OnDownloadProgressChanged(downloadProgressChangedEventArgs); } // Reset the bufferCount. bufferCount = 0; } } }
/// <summary> /// Raise DownloadProgressChanged event. If the status is Completed, then raise /// DownloadCompleted event. /// </summary> /// <param name="e"></param> protected virtual void OnDownloadProgressChanged( MultiThreadedWebDownloaderProgressChangedEventArgs e) { if (DownloadProgressChanged != null) { DownloadProgressChanged(this, e); } }
/// <summary> /// Raise DownloadProgressChanged event. If the status is Completed, then raise /// DownloadCompleted event. /// </summary> /// <param name="e"></param> protected virtual void OnDownloadProgressChanged( MultiThreadedWebDownloaderProgressChangedEventArgs e) { if (DownloadProgressChanged != null) { DownloadProgressChanged(this, e); } }
/// <summary> /// Handle the DownloadProgressChanged event of all the HttpDownloadClients, and /// calculate the download speed. /// </summary> void client_DownloadProgressChanged(object sender, HttpDownloadClientProgressChangedEventArgs e) { lock (locker) { DownloadedSize += e.Size; bufferCount++; if (bufferCount == BufferCountPerNotification) { if (DownloadProgressChanged != null) { int speed = 0; DateTime current = DateTime.Now; TimeSpan interval = current - lastNotificationTime; if (interval.TotalSeconds < 60) { speed = (int)Math.Floor((this.DownloadedSize - this.lastNotificationDownloadedSize) / interval.TotalSeconds); } lastNotificationTime = current; lastNotificationDownloadedSize = this.DownloadedSize; var downloadProgressChangedEventArgs = new MultiThreadedWebDownloaderProgressChangedEventArgs( DownloadedSize, TotalSize, speed); this.OnDownloadProgressChanged(downloadProgressChangedEventArgs); } // Reset the bufferCount. bufferCount = 0; } } }