码:
var dl = new BackgroundDownloader(); dl.CostPolicy = BackgroundTransferCostPolicy.Always; file = await localSoundsFolder.CreatefileAsync(name,CreationCollisionoption.ReplaceExisting); if (file != null) { var d = dl.CreateDownload(new Uri(uriTodownloadFrom,UriKind.relativeOrabsolute),file); d.Priority = BackgroundTransferPriority.High; var progressCallback = new Progress<DownloadOperation>(x => DownloadProgress(x,sc)); try { await d.StartAsync().AsTask(cancellationToken.Token,progressCallback); //After this line it doesn't progress! CancellationTokenSource token = Utility.cancellationList[sc]; if (token != null) { token.Cancel(); Utility.cancellationList.Remove(sc); DeBUG.Writeline("The sc has been removed from the download List"); } } catch { return; } }private static voID DownloadProgress(DownloadOperation download,SoundClass sc){ DeBUG.Writeline("Callback"); var value = download.Progress.BytesReceived * 100 / download.Progress.TotalBytesToReceive; DeBUG.Writeline("The bytesReceived is {0} and total bytes is {1}",download.Progress.BytesReceived.ToString(),download.Progress.TotalBytesToReceive.ToString()); new System.Threading.ManualresetEvent(false).WaitOne(10); sc.downloadProgress = value; if (download.Progress.Status == BackgroundTransferStatus.Completed || value >= 100) { DeBUG.Writeline("DONE donwloading the file {0}",download.Resultfile.name); DeBUG.Writeline("The file name happened to be to be added was " + download.Resultfile.name); string filename = download.Resultfile.name; }}
行等待d.StartAsync().AsTask(cancellationToken.Token,progressCallback);该计划不进行.而且也没有错误.这不仅适用于手机在桌面上完美运行!我错过了什么?
解决方法 BackgroundDownloader和我认为windows UWP中的所有BackgroundTasks都难以使用它们. 您必须首先在当前解决方案中创建一个新的解决方案作为windows运行时组件. 之后,您必须通过Package.AppxManifest链接它. 呃,不要忘记将运行时组件作为主项目的参考. 如果你做这些事情,希望它必须是有效的.但请确保您有一个RuntimeComponent并将其链接到您的项目中 总结以上是内存溢出为你收集整理的c# – BackgroundDownloader不适用于Windows 10移动UWP?全部内容,希望文章能够帮你解决c# – BackgroundDownloader不适用于Windows 10移动UWP?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)