private void ImageDownloaders_PropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case "DownloadingProgress": //long pre_calc_max = MaximumProgressBar == -1 ? 1 : MaximumProgressBar; double scale = MaximumProgressBar == 0 ? 1 : (MaximumProgressBar / 100); TotalDownloadingProgress.TotalDownloadingProgressValue = ImageDownloaders.Sum(x => x.CurrentBytesReceived) / scale; RaisePropertyChanged(nameof(TotalDownloadingProgress)); break; } }
public async Task DownloadAllAsync() { ImageDownloaders.Where(x => x.TotalBytesToReceive == 0).AsParallel().ForAll(x => x.TotalBytesToReceive = GetTotalBytesReceive(x?.Url)); ImageDownloaders.AsParallel().ForAll(x => x.DownloadingState = DownloadingState.Downloading); List <Task> tasks = new List <Task>(); foreach (var vm in ImageDownloaders) { tasks.Add(vm.StartDownloadAsync("All")); } await Task.WhenAll(tasks); ImageDownloaders.AsParallel().ForAll(x => x.DownloadingState = DownloadingState.Completed); }