private async void UpdateStats(CancellationToken cancel) { long lastDownloaded = 0; long lastUploaded = 0; long lastDownloadSample = 0; int lastSpeed = 0; DateTime nextUpdate = DateTime.UtcNow.AddSeconds(3); string dcache = Util.Text.FormatBytes(0), ucache = Util.Text.FormatBytes(0), dscache = ""; long cacheStorage = -1; int lastPurge = 0; while (true) { try { await Task.Delay(1000, cancel); } catch (TaskCanceledException) { return; } if (lastRequest != null) { lock (activeRows) { labelLastRequest.Text = lastRequest; lastRequest = null; } } bool update = false; var bytesDownloaded = this.bytesDownloaded; if (lastDownloaded != bytesDownloaded) { lastDownloaded = bytesDownloaded; dcache = Util.Text.FormatBytes(lastDownloaded); update = true; } if (lastUploaded != bytesUploaded) { lastUploaded = bytesUploaded; ucache = Util.Text.FormatBytes(lastUploaded); update = true; } if (purgeProgress != null) { if (purgeProgress.purged == purgeProgress.total) { lastPurge = 0; purgeProgress = null; } else { if (labelCached.Enabled) { labelCached.Enabled = false; } if (lastPurge != 0 || (float)purgeProgress.purged / purgeProgress.total < 0.25f) //only show progress if it'll take more than a few seconds to complete { if (lastPurge != purgeProgress.purged) { lastPurge = purgeProgress.purged; labelCached.Text = string.Format("{0:#,##0} of {1:#,##0}", lastPurge, purgeProgress.total); } } } } else if (cacheStorage != this.cacheStorage) { cacheStorage = this.cacheStorage; labelCached.Text = Util.Text.FormatBytes(cacheStorage); } if (bytesDownloaded > 0) { var now = DateTime.UtcNow; if (now > nextUpdate) { var s = now.Subtract(nextUpdate).TotalSeconds + 3; if (s > 0) { var sample = (int)((bytesDownloaded - lastDownloadSample) / s + 0.5); if (sample < 1024) { sample = 0; } if (sample != lastSpeed) { lastSpeed = sample; if (sample != 0) { dscache = " @ " + Util.Text.FormatBytes(sample) + "/s"; } else { dscache = ""; } update = true; } nextUpdate = now.AddSeconds(3); lastDownloadSample = bytesDownloaded; } } } if (update) { labelDownloaded.Text = ucache + " / " + dcache + dscache; } } }
void Cache_PurgeProgress(object sender, Net.AssetProxy.Cache.PurgeProgressEventArgs e) { purgeProgress = e; }