【发布时间】:2014-04-04 14:29:55
【问题描述】:
我的程序正在使用队列以使用 webClient 的异步方法一一下载文件列表。 它看起来像这样:
public void DownloadFile()
{
if (_downloadUrls.Any())
{
var urlAddress = _downloadUrls.Dequeue();
//Irrelevant code that gets correct URL, and location from queue _downloadUrls
try
{
// Start downloading the file
webClient1.DownloadFileAsync(URL, location);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("complete!");
}
}
这是我的 DownloadFileCompleted 代码:
private void webClient1_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled == true)
{
// MessageBox.Show("Download has been canceled.");
}
else
{
DownloadFile();
}
}
问题是如何将有关文件名的信息传递给 DownloadFileCompleted? 我想更改下载文件的最后访问日期,以便它们与服务器上的相同,我只能在 webClient1_DownloadFileCompleted 中执行此操作,但我不知道哪个文件触发了事件 DownloadFileCompleted。如何将此信息传递给 DownloadFileCompleted(最好作为参数中的字符串)。
【问题讨论】: