我有一些文件需要在app启动时下载(首次运行).我在Windows 8中使用Background Downloader.这就是我使用它的方式:
BackgroundDownloader downloader = new BackgroundDownloader();
List<DownloadOperation> operations = new List<DownloadOperation>();
foreach (FileInfo info in infoFiles)
{
Windows.Storage.ApplicationData.Current.LocalFolder;
foreach (string folder in info.Folders)
{
currentFolder = await currentFolder.CreateFolderAsync(folder, CreationCollisionOption.OpenIfExists);
}
//folder hierarchy created, save the file
StorageFile file = await currentFolder.CreateFileAsync(info.FileName, CreationCollisionOption.ReplaceExisting);
DownloadOperation op = downloader.CreateDownload(new Uri(info.Url), file);
activeDownloads.Add(op);
operations.Add(op);
}
foreach (DownloadOperation download in operations)
{
//start downloads
await HandleDownloadAsync(download, true);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用时,BackgroundDownloader.GetCurrentDownloadsAsync();我只发现了一个后台下载.所以我删除了上面的await运算符,让它们异步启动.
但是我需要知道所有文件何时完成,所以我可以设置进度条.
我需要一种方法来下载多个文件,发现所有文件BackgroundDownloader.GetCurrentDownloadsAsync();并知道所有下载完成的时间.
private async Task HandleDownloadAsync(DownloadOperation download, bool start)
{ …Run Code Online (Sandbox Code Playgroud)