I'm trying to download a file using this code on a windows 10 universal app:
await downloadOperation.StartAsync().AsTask(token, progressCallback);
it's working on pc but on mobile sometimes it's doesn't start downloading and not even giving an exception until I restart the mobile. Is it a bug in the system or I'm missing something?
Edit 1:
the task's status is "waiting for activation" so it's not throwing an exception. it's just waiting and not starting until I restart the phone I'm trying always with the same url and I don't have this problem on the pc. It's about the phone only. The task's properties are the following:
If you're having trouble launching Microsoft Store, here are some things to try: Check for connection problems and make sure that you're signed in with a Microsoft account. Make sure Windows has the latest update: Select Start , then select Settings > Update & Security > Windows Update > Check for Updates.
Run the Troubleshooter First, open Settings > Update & Security and then select Troubleshoot. Select Additional Troubleshooters and scroll down the page. Select Windows Store Apps, and in the box beneath it select Run the troubleshooter.
I found the problem finally. when I start a download operation and close the application without cancelling the operation the BackgroundDownloader keeps the operation for the next application start. when the number of download operations reach the maximum allowed simultaneous operations(I think 5) the next operations will be on the waiting list() till the previous operations finish. so I had to stop all the uncompleted operations when the application starts like this:
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);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With