public void RunPoller() { if (downloadPollerTask == null || downloadPollerTask.IsCompleted) { downloadPollerTask = Task.Run(async() => { while (HasWork()) { try { await Task.Delay(1000); DownloadHelper helper; if (!string.IsNullOrWhiteSpace(currentId) && downloads.TryGetValue(currentId, out helper)) { if (helper.State == DownloadHelper.DownloadState.Canceled) { continue; } if (helper.State == DownloadHelper.DownloadState.Downloading) { continue; } if (helper.State != DownloadHelper.DownloadState.Completed) { await helper.StartDownload(); continue; } } var next = downloads.FirstOrDefault(); if (string.IsNullOrWhiteSpace(next.Key)) { continue; } helper = next.Value; if (helper.State == DownloadHelper.DownloadState.Canceled) { continue; } if (helper.State == DownloadHelper.DownloadState.Downloading) { continue; } if (helper.State != DownloadHelper.DownloadState.Completed) { await helper.StartDownload(); } } catch (Exception ex) { LogManager.Shared.Report(ex); } } }); } }
public void StopAllOthers(Song song) { var first = playerQueue.FirstOrDefault(); if (first.Key != song.Id && !string.IsNullOrWhiteSpace(first.Key)) { playerQueue.Remove(first.Key); } var items = playerQueue.ToList(); foreach (var item in items) { if (item.Key != song.Id) { item.Value.Stop(); } } }