BiliRanking.Core.Download.MultiThreadedWebDownloader.client_DownloadProgressChanged C# (CSharp) Method

client_DownloadProgressChanged() static private method

Handle the DownloadProgressChanged event of all the HttpDownloadClients, and calculate the download speed.
static private client_DownloadProgressChanged ( object sender, DownloadProgressChangedEventArgs e ) : void
sender object
e DownloadProgressChangedEventArgs
return void
        void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            lock (locker)
            {
                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.CachedSize-
                            this.lastNotificationDownloadedSize) / interval.TotalSeconds);
                    }

                    lastNotificationTime = current;
                    lastNotificationDownloadedSize = this.DownloadedSize + this.CachedSize;

                    var downloadProgressChangedEventArgs =
                        new DownloadProgressChangedEventArgs(
                            DownloadedSize, TotalSize, speed);
                    this.OnDownloadProgressChanged(downloadProgressChangedEventArgs);
                }

            }
        }