public Task StartDownloadAsync()
        {
            if (Settings.ConcurrentDownloads == 0)
            {
                Settings.ConcurrentDownloads = 4;
            }
            _downloadTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(Settings.ConcurrentDownloads);
            TaskFactory factory = new TaskFactory(_downloadTaskScheduler);

            var syncContext = SynchronizationContext.Current;

            // start all using limited task scheduler
            foreach (var item in DownloadItems)
            {
                item.DownloadAsync(factory).ContinueWith((task) => {
                    if (RemoveItemWhenDowloaded && item.Completed == true && item.Failed == false)
                    {
                        syncContext.Send((o) => { DownloadItems.Remove(item); }, null);
                    }
                });
            }

            return(Task.Run(() =>
            {
                WaitAll();
            }));
        }
Esempio n. 2
0
 public void Delete(DownloadItems items)
 {
     foreach (var item in items)
     {
         DownloadItems.Remove(item);
         item.CurrentDownloadTaskCts?.Cancel();
         item.Status = DownloadStatusEnum.Cancel;
     }
 }
Esempio n. 3
0
 public void DeleteAllSuccess()
 {
     for (var i = 0; i < DownloadItems.Count; i++)
     {
         var item = DownloadItems[i];
         if (item.Status == DownloadStatusEnum.Success ||
             item.Status == DownloadStatusEnum.Skip)
         {
             DownloadItems.Remove(item);
             i--;
         }
     }
 }
 private void DeleteAllButtonOnClick(object sender, RoutedEventArgs e)
 {
     for (var i = 0; i < DownloadItems.Count; i++)
     {
         var item = DownloadItems[i];
         if (item.DownloadStatus == DownloadStatusEnum.Success)
         {
             DownloadItems.Remove(item);
             i--;
         }
     }
     ContextMenuPopup.IsOpen = false;
 }