Ejemplo n.º 1
0
        protected virtual void Dispose(bool disposing) {
            if (!disposing)
                return;
            if (_timer == null)
                return;

            _timer.Dispose();
            _timer = null;
        }
Ejemplo n.º 2
0
        static Timer SetupTransferProgress(IWebClient webClient, ITransferProgress transferProgress) {
            var lastTime = Tools.Generic.GetCurrentUtcDateTime;
            long lastBytes = 0;

            transferProgress.Progress = 0;
            transferProgress.FileSizeTransfered = 0;

            webClient.DownloadProgressChanged +=
                (sender, args) => {
                    var bytes = args.BytesReceived;
                    var now = Tools.Generic.GetCurrentUtcDateTime;

                    transferProgress.Progress = args.ProgressPercentage;
                    transferProgress.FileSizeTransfered = bytes;

                    if (lastBytes != 0) {
                        var timeSpan = now - lastTime;
                        var bytesChange = bytes - lastBytes;

                        if (timeSpan.TotalMilliseconds > 0)
                            transferProgress.Speed = (long) (bytesChange/(timeSpan.TotalMilliseconds/1000.0));
                    }

                    lastBytes = bytes;
                    lastTime = now;
                };

            webClient.DownloadFileCompleted += (sender, args) => { transferProgress.Completed = true; };

            var timer = new TimerWithElapsedCancellation(500, () => {
                if (!transferProgress.Completed
                    && Tools.Generic.LongerAgoThan(lastTime, timeout)) {
                    webClient.CancelAsync();
                    return false;
                }
                return !transferProgress.Completed;
            });
            return timer;
        }
Ejemplo n.º 3
0
 public Snow(Canvas canvas, IEventAggregator eventBus) {
     _timer = new TimerWithElapsedCancellation(TimeSpan.FromMilliseconds(Interval), OnTimerTicker, null, false);
     _canvas = canvas;
     eventBus.Subscribe(this);
 }
Ejemplo n.º 4
0
 public RepoWatcher(StatusRepo repo) {
     _timer = new TimerWithElapsedCancellation(TimerTime, () => {
         repo.UpdateTotals();
         return true;
     });
 }
Ejemplo n.º 5
0
            protected virtual void Dispose(bool disposing) {
                if (!disposing)
                    return;

                if (_disposed)
                    return;
                _timer.Dispose();
                _timer = null;

                _disposed = true;
            }