Мой код для загрузки нескольких файлов из веб-источника получит имя файла с сервера и затем начнет загрузку. Однако, как только он захватывает имя файла для второго в очереди, он прекращает загрузку и в конечном итоге истекает время ожидания. Что мне здесь не хватает? Любые советы приветствуются.
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string[] s = (string[])e.Argument;
for (int x = 0; x < s.Length; x++) {
using (WebClient client = new WebClient())
{
client.OpenRead(s[x]);
string header_contentDisposition = client.ResponseHeaders["content-disposition"];
string filename = new ContentDisposition(header_contentDisposition).FileName;
string filedownload = AppDomain.CurrentDomain.BaseDirectory + filename;
var url = new Uri(s[x]);
client.DownloadFileAsync(url, filedownload);
client.Dispose();
/* HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
var wresp = (HttpWebResponse)request.GetResponse();
using (Stream file = File.OpenWrite(filename))
{
wresp.GetResponseStream().CopyTo(file);
}
}
*/
//client.DownloadFileAsync(url, filedownload);
}
}
}