private void RetryDownloads(IEnumerable <DownloadOperation> downloads)
        {
            BackgroundDownloader downloader = CompletionGroupTask.CreateBackgroundDownloader();

            foreach (DownloadOperation download in downloads)
            {
                DownloadOperation        download1 = downloader.CreateDownload(download.RequestedUri, download.ResultFile);
                Task <DownloadOperation> startTask = download1.StartAsync().AsTask();
            }

            downloader.CompletionGroup.Enable();
        }
Ejemplo n.º 2
0
        private async Task RetryDownloadsAsync(IEnumerable <DownloadOperation> downloadsToRetry)
        {
            BackgroundDownloader downloader = CompletionGroupTask.CreateBackgroundDownloader();

            foreach (DownloadOperation downloadToRetry in downloadsToRetry)
            {
                // Retry with the same uri, but save to a different file name.
                string originalName = downloadToRetry.ResultFile.Name;
                string newName      = originalName.Insert(originalName.LastIndexOf('.'), "_retried");
                await downloadToRetry.ResultFile.RenameAsync(newName, NameCollisionOption.ReplaceExisting);

                DownloadOperation download = downloader.CreateDownload(downloadToRetry.RequestedUri, downloadToRetry.ResultFile);

                // We do not await on background transfer asynchronous tasks, since await will only
                // finish after the entire transfer is complete, which may take a very long time.
                // The completion of these downloads will be handled by a future CompletionGroupTask instance.
                Task <DownloadOperation> startTask = download.StartAsync().AsTask();
            }

            downloader.CompletionGroup.Enable();
        }