Windows phone 8.1 在WP8.1中下载多个文件
我正在开发一个应用程序,可以下载多个文件,但我每次只能下载一个文件 我在点击按钮下载文件时实现的代码如下:Windows phone 8.1 在WP8.1中下载多个文件,windows-phone-8.1,Windows Phone 8.1,我正在开发一个应用程序,可以下载多个文件,但我每次只能下载一个文件 我在点击按钮下载文件时实现的代码如下: private async void ButtonDownload_Click_1(object sender, RoutedEventArgs e) { string uri = "download url****************************"; StorageFolder folder = ApplicationData.Current.Local
private async void ButtonDownload_Click_1(object sender, RoutedEventArgs e)
{
string uri = "download url****************************";
StorageFolder folder = ApplicationData.Current.LocalFolder;
if (folder != null)
{
StorageFile file = await folder.CreateFileAsync(++fileNo + "stVideo.mp4", CreationCollisionOption.GenerateUniqueName);
downloadOperation = backgroundDownloader.CreateDownload(new Uri(uri), file);
Progress<DownloadOperation> progress = new Progress<DownloadOperation>(progressChanged);
cancellationToken = new CancellationTokenSource();
try
{
TextBlockStatus.Text = "Initializing...";
await downloadOperation.StartAsync().AsTask(cancellationToken.Token, progress);
}
catch (TaskCanceledException)
{
TextBlockStatus.Text = "Download canceled.";
downloadOperation.ResultFile.DeleteAsync().AsTask().Wait();
ButtonDownload.IsEnabled = true;
downloadOperation = null;
}
}
}
但我无法想出一个下载多个文件的解决方案
请向我详细说明如何摆脱这个问题
如果您单击了两次或更多次,则表示感谢。您可以使用一个进度处理程序创建多个下载。 创建下载操作项时,系统将生成唯一的id-Guid。 您可以确定在progressChanged中下载哪些项目 据我所知:
我创建了用于后台下载的简单示例。您可以从下载示例,谢谢。您可以提供一些代码片段,我可以开始多次下载吗
private void progressChanged(DownloadOperation downloadOperation)
{
int progress = (int)(100 * ((double)downloadOperation.Progress.BytesReceived / (double)downloadOperation.Progress.TotalBytesToReceive));
TextBlockProgress.Text = String.Format("{0} of {1} kb. downloaded - %{2} complete.", downloadOperation.Progress.BytesReceived / 1024, downloadOperation.Progress.TotalBytesToReceive / 1024, progress);
ProgressBarDownload.Value = progress;
switch (downloadOperation.Progress.Status)
{
case BackgroundTransferStatus.Running:
{
TextBlockStatus.Text = "Downloading...";
break;
}
case BackgroundTransferStatus.Completed:
{
TextBlockStatus.Text = "Download complete.";
downloadOperation = null;
break;
}
case BackgroundTransferStatus.PausedByApplication:
{
TextBlockStatus.Text = "Download paused.";
break;
}
case BackgroundTransferStatus.PausedCostedNetwork:
{
TextBlockStatus.Text = "Download paused because of metered connection.";
break;
}
case BackgroundTransferStatus.PausedNoNetwork:
{
TextBlockStatus.Text = "No network detected. Please check your internet connection.";
break;
}
case BackgroundTransferStatus.Error:
{
TextBlockStatus.Text = "An error occured while downloading.";
break;
}
}
}