public virtual void TransferEnd()
        {
            if (handler == null)
            {
                return;
            }
            DateTime       now    = DateTime.Now;
            TransferStatus status = new TransferStatus(newlyTransferredBytes,
                                                       transferredBytes, totalBytes, (now - lastCheckpoint).TotalSeconds, (now - startCheckpoint).TotalSeconds);

            status.SetInstantaneousBytes(this.CreateCurrentInstantaneousBytes(newlyTransferredBytes, now));
            handler(sender, status);
        }
        protected override void DoBytesTransfered(int bytes)
        {
            transferredBytes      += bytes;
            newlyTransferredBytes += bytes;
            DateTime          now = DateTime.Now;
            IList <BytesUnit> currentInstantaneousBytes = this.CreateCurrentInstantaneousBytes(bytes, now);

            this.lastInstantaneousBytes = currentInstantaneousBytes;
            if (newlyTransferredBytes >= this.interval || transferredBytes == totalBytes)
            {
                TransferStatus status = new TransferStatus(newlyTransferredBytes,
                                                           transferredBytes, totalBytes, (now - lastCheckpoint).TotalSeconds, (now - startCheckpoint).TotalSeconds);
                status.SetInstantaneousBytes(currentInstantaneousBytes);
                handler(sender, status);
                // Reset
                newlyTransferredBytes = 0;
                lastCheckpoint        = now;
            }
        }
Пример #3
0
        protected override void DoBytesTransfered(int bytes)
        {
            Interlocked.Add(ref transferredBytes, bytes);
            Interlocked.Add(ref newlyTransferredBytes, bytes);
            DateTime          now = DateTime.Now;
            IList <BytesUnit> currentInstantaneousBytes = this.CreateCurrentInstantaneousBytes(bytes, now);

            this.lastInstantaneousBytes = currentInstantaneousBytes;

            long _newlyTransferredBytes = Interlocked.Read(ref newlyTransferredBytes);
            long _transferredBytes      = Interlocked.Read(ref transferredBytes);

            if (_newlyTransferredBytes >= this.interval && _transferredBytes < totalBytes)
            {
                if (Interlocked.CompareExchange(ref newlyTransferredBytes, 0, _newlyTransferredBytes) == _newlyTransferredBytes)
                {
                    TransferStatus status = new TransferStatus(_newlyTransferredBytes,
                                                               _transferredBytes, totalBytes, (now - lastCheckpoint).TotalSeconds, (now - startCheckpoint).TotalSeconds);
                    status.SetInstantaneousBytes(currentInstantaneousBytes);
                    handler(sender, status);
                    lastCheckpoint = now;
                }
            }
        }