【发布时间】:2015-04-29 07:14:36
【问题描述】:
我用 C# 制作了一个下载程序。它是一个队列下载器。 你可以在这里看到它是如何工作的:点击Express Downloader
有没有更快的下载方法? 这是我使用的方法,它必须支持恢复支持。
private void Download(object startPoint)
{
try
{
try
{
//int startPointInt = Convert.ToInt32(startPoint);
Int64 startPointInt = Convert.ToInt64(startPoint);
webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.AddRange(startPointInt);
webRequest.Credentials = CredentialCache.DefaultCredentials;
webResponse = (HttpWebResponse)webRequest.GetResponse();
Int64 fileSize = webResponse.ContentLength;
strResponse = webResponse.GetResponseStream();
if (startPointInt == 0)
{
strLocal = new FileStream(txtPath.Text + "\\" + filename, FileMode.Create, FileAccess.Write, FileShare.None);
}
else
{
strLocal = new FileStream(txtPath.Text + "\\" + filename, FileMode.Append, FileAccess.Write, FileShare.None);
}
int bytesSize = 0;
byte[] downBuffer = new byte[4096];
while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
strLocal.Write(downBuffer, 0, bytesSize);
this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strLocal.Length, fileSize + startPointInt });
if (goPause == true)
{
break;
}
}
}
catch { }
}
finally
{
strResponse.Close();
strLocal.Close();
}
}
【问题讨论】:
-
获得更快的宽带?
-
@MattWilko 丁丁丁。我们有一个赢家!
-
你可以查看http压缩:compositecode.com/2009/03/24/…
-
使用
WebClient,它为您封装了所有这些工作,并拥有大量异步和同步方法 -
WebClient 糟透了,我无法下载超过 2GB 的文件...而且我的“on steam”下载速度大约为 13.4 MB/s...所以我希望我的程序以大约 13.4 MB/s 的速度下载速度也...