Example #1
0
        private void transferDataTransferred(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                DataTransferredEventHandler d = new DataTransferredEventHandler(transferDataTransferred);
                this.Invoke(d, new object[] { sender, e });
            }
            else
            {
                TransferInfo transfer = (TransferInfo)sender;
                progressBarTransfer.Maximum = (int)(transfer.TotalBytes / 1024);
                progressBarTransfer.Value   = (int)(transfer.BytesTransferred / 1024);

                long bytesPerSec = transfer.TransferSpeed;
                long secRemaining;
                long avgTransferSpeed = 1000 * transfer.BytesTransferred / transfer.ElapsedMilliseconds;
                if (avgTransferSpeed > 0)
                {
                    secRemaining = (transfer.TotalBytes - transfer.BytesTransferred) / avgTransferSpeed;
                }
                else
                {
                    secRemaining = 0;
                }

                TimeSpan timeRemaining = TimeSpan.FromSeconds((double)secRemaining);

                labelTransferSpeed.Text = String.Format(new FileSizeFormatProvider(), "{0:fs}/s", bytesPerSec);
                labelTransferTime.Text  = String.Format("{0:c} remaining", timeRemaining);
            }
        }
Example #2
0
        public void FireDataTransferredEvent()
        {
            long byteThisInterval = BytesTransferred - _lastBytesTransferred;
            long millis           = _speedStopwatch.ElapsedMilliseconds - _lastMillis;

            DataTransferredEventHandler handler = OnDataTransferred;

            if (handler != null)
            {
                handler(this, new DataTransferredEventArgs(byteThisInterval, millis));
            }

            _lastBytesTransferred = BytesTransferred;
            _lastMillis           = _speedStopwatch.ElapsedMilliseconds;
            if (millis > 0)
            {
                lock (_speedHistory)
                {
                    _speedHistory.Enqueue(1000 * byteThisInterval / millis);
                }
            }
        }