Reputation: 1716
I am using BackgroundTransferRequest
to download files, I have more than 6,500 mp3 that user can download them at once clicking on download all button Or user can download individual file.
I cannot add more than 25 files in download BackgroundTransferRequest
. What is the workaround with it to add more than 25 files in download queue.
When it reaches the level, the exception is
Unable to download. The application request limit has been reached
Code for adding in Queue, After all files are added. I am processing download.
transferFileName = aya.DownloadUri;
Uri transferUri = new Uri(Uri.EscapeUriString(aya.DownloadUri), UriKind.RelativeOrAbsolute);
BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);
transferRequest.Method = "GET";
string downloadFile = transferFileName.Substring(transferFileName.LastIndexOf("/") + 1);
Uri downloadUri = new Uri(downloadLocation + aya.ChapterID + "/" + downloadFile, UriKind.RelativeOrAbsolute);
transferRequest.DownloadLocation = downloadUri;
transferRequest.Tag = string.Format("{0},{1},{2}", downloadFile, aya.ID, aya.ChapterID);
transferRequest.TransferPreferences = TransferPreferences.AllowBattery;
BackgroundTransferService.Add(transferRequest);
Upvotes: 1
Views: 289
Reputation: 4198
You must attach an event handler to BackgroundTransferRequest.StatusChanged
. On appropriate state you must explicitly remove transfer from BackgroundTransferService
. As you may now, the requests have to be removed from BackgroundTransferService
manually. All that is explained in detail in introduction to background transfers on msdn.
You should create a queue of files to download, start with placing first 25 transfers in BackgroundTransferService
and after the BackgroudTransferService.Remove(..)
, you can start next transfer from your queue.
Upvotes: 2