Windows 10 DownloadOperation applications not starting

I am trying to upload a file using this code in a universal Windows 10 application:

await downloadOperation.StartAsync().AsTask(token, progressCallback); 

It works on a PC, but sometimes it doesn’t start on a mobile phone and does not even give an exception until I restart the mobile. Is this a system error or is something missing?

Change 1:

the task status is “waiting for activation”, so it does not throw an exception. it just waits and won't start until I restart the phone I always try with the same URL and I don't have this problem on the PC. This is just about the phone. The properties of the task are as follows:

+6
source share
1 answer

I finally found the problem. when I start the download operation and close the application without canceling the operation, BackgroundDownloader saves the operation to start the next application. when the number of loading operations reaches the maximum allowable simultaneous operations (I think 5), the following operations will be on the waiting list () until the previous operations are completed. so I had to stop all pending operations when the application starts as follows:

 Task.Run(async () => { var downloads = await BackgroundDownloader.GetCurrentDownloadsAsync(); foreach (var download in downloads) { CancellationTokenSource cts = new CancellationTokenSource(); download.AttachAsync().AsTask(cts.Token); cts.Cancel(); } var localFolder = ApplicationData.Current.LocalFolder; var files = await localFolder.GetFilesAsync(); files = files.Where(x => x.Name.EndsWith("_")).ToList(); foreach (StorageFile file in files) { await file.DeleteAsync(StorageDeleteOption.PermanentDelete); } }); 
+3
source

All Articles