私はアプリのスタートアップ(最初の実行)でダウンロードする必要があるいくつかのファイルがあります。私は窓8 にバックグラウンドダウンローダーを使用しています これは私がそれを使用する方法です:私はBackgroundDownloader.GetCurrentDownloadsAsync();
を使用しようとするとバックグラウンドダウンローダーのウィンドウ8複数のファイル
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);
}
私が発見した唯一のバックグラウンドダウンロードを取得します。そこで、上記の待ち受けオペレータを非同期に開始するように削除しました。
しかし、私はすべてのファイルが終了したので、プログレスバーを設定することができます。
複数のファイルをダウンロードし、すべてをBackgroundDownloader.GetCurrentDownloadsAsync();
で検索し、すべてのダウンロードがいつ完了したかを知る必要があります。あなたは、特に、すべてのアプリの起動時にファイルを再度ダウンロードする必要がある場合
private async Task HandleDownloadAsync(DownloadOperation download, bool start)
{
try
{
Debug.WriteLine("Running: " + download.Guid, NotifyType.StatusMessage);
// Store the download so we can pause/resume.
activeDownloads.Add(download);
Progress<DownloadOperation> progressCallback = new Progress<DownloadOperation>(DownloadProgress);
if (start)
{
// Start the download and attach a progress handler.
await download.StartAsync().AsTask(cts.Token, progressCallback);
}
else
{
// The download was already running when the application started, re-attach the progress handler.
await download.AttachAsync().AsTask(cts.Token, progressCallback);
}
ResponseInformation response = download.GetResponseInformation();
Debug.WriteLine(String.Format("Completed: {0}, Status Code: {1}", download.Guid, response.StatusCode),
NotifyType.StatusMessage);
}
catch (TaskCanceledException)
{
Debug.WriteLine("Canceled: " + download.Guid, NotifyType.StatusMessage);
}
catch (Exception ex)
{
if (!IsExceptionHandled("Execution error", ex, download))
{
throw;
}
}
finally
{
activeDownloads.Remove(download);
}
}
あなたが見てきました[クイックスタート:ファイルのダウンロード](http://msdn.microsoft.com/en-us/library/windows/apps/jj152726.aspx改訂版は、次のようになります)? – Harrison