목록 상자에 다음과 같은 링크가 가득 찼습니다 : http://example.com/sorted/Avicii/Avicii+-+Wake+Me+Up.mp3 그리고 나는 그들을 모두 같은 시간에 다운로드하고 싶습니까? 방법같은 시간에 여러 파일 내려 받기
당신이 윈폼 또는 ASP.NET 작업하는 경우 확실 해요using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
namespace SillyCSharpNameSpace
{
public class VerboseDownloaderClassName
{
private string downloadFile(string url, string localDir)
{
try
{
var localPath = Path.Combine(localDir, Path.GetFileName(url));
using (var wc = new WebClient())
{
wc.DownloadFile(url, localPath);
return localPath;
}
}
catch (Exception e)
{
Console.WriteLine(e);
return null;
}
}
public void DownloadAll(List<string> urls)
{
urls.AsParallel()
.Where(url => !string.IsNullOrWhiteSpace(url))
.WithDegreeOfParallelism(20)
.Select(url => downloadFile(url, "."));
}
}
}
당신이 알아낼 수 : 이 코드는 I는 다음과 같이 할 수있는 하나의 파일
private void txtUrl_TextChanged(object sender, EventArgs e)
{
try
{
// function that enter the file name automatically in the savefiledialog.
Uri uri = new Uri(txtUrl.Text);
// Save the file name to the string.
filename = Path.GetFileName(uri.LocalPath);
}
catch
{
// no need need an exception message.
}
}
private void DownloadFile(string url, string save)
{
using (var client = new WebClient())
{
// Run code every time the download changes.
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Changed);
// Run codes when file download has been completed.
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
client.DownloadFileAsync(new Uri(url), save);
첫 번째 제안 : 지금까지 시도한 코드를 게시하십시오. 두 번째 제안 : 정확히 어디에서 붙어 있는지 설명하십시오. – DigiFriend
나는 하나의 파일을 다운로드하는 방법이 있지만 실용적인 @DigiFriend을 가지고 있지 않다. – Elmissouri
루프는 당신 친구 야. 비동기 메소드와 같습니다. – DigiFriend