I am writing Windows Phone 8.1 Silverlight application.

I am using DownloadOperation and UploadOperation from Windows.Networking.BackgroundTransfer namespace for downloading/uploading images, files... And all work successfully on Windows Phone 8.1 devices/emulators, but not on Windows Phone 10 emulators.

The problem is that DownloadOperation / UploadOperation doesn't start downloading / uploading and not even giving progress callbacks or even an exception... It looks like that app begins sleeping after call .StartAsync()..

This is an example of how I am using this API:

            StorageFile destinationFile;
            try
            {
                destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(item.Name, 
                    CreationCollisionOption.ReplaceExisting);
            }
            catch (FileNotFoundException ex)
            {
                if (Debugger.IsAttached) Debugger.Break();
                return;
            }

            var backgroundDownload = _backgroundDownloader.CreateDownload(new Uri(item.Url), destinationFile);
            backgroundDownload.CostPolicy = BackgroundTransferCostPolicy.Always;

            try
            {
                var progresscallback = new Progress<DownloadOperation>(operation =>
                {
                    if (operation.Progress.TotalBytesToReceive != 0)
                    {
                        var progress = 100 * operation.Progress.BytesReceived / (double)operation.Progress.TotalBytesToReceive;
                        item.Progress = progress;
                    }                        
                });

                await backgroundDownload.StartAsync().AsTask(_cancellationTokenSource.Token, progresscallback);
                var info = backgroundDownload.GetResponseInformation();
                if (info.StatusCode == 200 || info.StatusCode == 206)
                {
                    ImagesToDownload.Remove(item);
                    DownloadedImages.Insert(0, item);
                }
                else
                {
                    if (Debugger.IsAttached) Debugger.Break();
                }
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached) Debugger.Break();
            }
        }

I have seen that some other guys have the same problems: BackgroundUploader and BackgroundDownloader in Windows 10 mobile

and windows 10 apps DownloadOperation not starting

But I didn't find a solution how to resolve this problem? Cancelling of uncompleted operations and device restart doesn't help.

Help how to force to work DownloadOperation on Windows Phone 10 emulators/devices?

My small test Windows Phone 8.1 Silverligth app in which DownloadOperation works on Windows Phone 8.1 devices / emaulators, but not on Windows Phone 10 emulators

In this test app I can reproduce this bug even after first deployment of application when I am trying to download first 4 images...

0

There are 0 best solutions below