Windows.Networking.BackgroundTransfer.DownloadOperation在Windows Phone 10中不起作用(但在Windows Phone 8.1上成功运行)

时间:2016-01-28 15:47:13

标签: windows-phone-8.1 windows-10 windows-10-mobile background-transfer

我正在编写Windows Phone 8.1 Silverlight应用程序。

我在Windows.Networking.BackgroundTransfer命名空间中使用DownloadOperation和UploadOperation来下载/上传图像,文件...... 所有这些都在Windows Phone 8.1设备/模拟器上成功完成,但在Windows Phone 10模拟器上无法成功。

问题是DownloadOperation / UploadOperation没有开始下载/上传,甚至没有提供进度回调甚至异常...看起来该应用程序在调用后开始休眠.StartAsync()..

这是我如何使用此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();
            }
        }

我看到其他一些人有同样的问题: BackgroundUploader and BackgroundDownloader in Windows 10 mobile

windows 10 apps DownloadOperation not starting

但是我找不到解决方法如何解决这个问题?取消未完成的操作和设备重启无济于事。

帮助如何强制在Windows Phone 10模拟器/设备上运行DownloadOperation?

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

在这个测试应用程序中,即使首次部署应用程序后,我也可以重现此错误,当我尝试下载前4个图像时...

0 个答案:

没有答案