public void Update(CancellationToken cancellationToken) { while (true) { if (cancellationToken.IsCancellationRequested) { break; } var status = this.state.LibtorrentSession.QueryStatus(); try { uiContext.Send(x => { if (mainlist.SelectedIndex == -1) { ResetDataContext(); } if (info_canvas.SelectedIndex == 1) { ReDrawGraph(); } string dsp = Utility.PrettifySpeed(status.DownloadRate); string usp = Utility.PrettifySpeed(status.UploadRate); this.DownloadStatus.Text = string.Format("D: {0} T: {1}", dsp, Utility.PrettifyAmount(status.TotalDownload)); this.UploadStatus.Text = string.Format("U: {0} T: {1}", usp, Utility.PrettifyAmount(status.TotalUpload)); this.DHTStatus.Text = string.Format("DHT Peers: {0}", status.DhtNodes); this.Title = string.Format("ByteFlood [D: {0}, U: {1}]", dsp, usp); status.Dispose(); this.ElementsColor = Utility.WindowsAero.ColorizationColor.ToWPFColor(); }, null); if (App.Settings.PreventStandbyWithActiveTorrents && state.ActiveTorrentCount > 0) { if (Utility.IsRunningOnBatteries && App.Settings.AllowStandbyOnBatteryPower) { Utility.UndoDisableSleep(); } else { Utility.DisableSleep(); } } else { Utility.UndoDisableSleep(); } // TODO: Update theses values only when they are really changed. state.NotifyChanged("DownloadingTorrentCount", "SeedingTorrentCount", "InactiveTorrentCount", "ActiveTorrentCount", "FinishedTorrentCount"); if (ticks >= 60) //1 min { state.SaveState(); ticks = 0; } else { ticks++; } } catch { } Thread.Sleep(1000); } }