我想通过点击按钮从互联网上下载文件并保存在Windows手机中的隔离存储中。但由于我有多个文件要从互联网上下载,所有下载必须按顺序进行,以便用户可以看到进度并在下载后立即访问它们。
public void Button1_Click(object sender, EventArgs e)
{
foreach(string url in urlarray)
{
DownloadFile(url);
}
}
void DownloadFile(string url)
{
WebClient downloadfile = new WebClient();
downloadfile.OpenReadCompleted += downloadfile_OpenReadCompleted;
downloadfile.OpenReadAsync(new Uri(url, UriKind.Absolute));
}
void downloadfile_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
//Save to isolated storage
}
现在,如果这是代码,将抛出隔离存储异常。所以我想使用Dispatcher.BeginInvoke(),但我不知道如何使用它。而且我也想下载并保存,没有任何例外。有人可以帮我吗?提前谢谢。