|
楼主 |
发表于 2020-7-17 17:15:01
|
显示全部楼层
private WebRequest httpRequest;
private WebResponse httpResponse;
private byte[] buffer;
private Thread downloadThread;
Stream ns;
private FileStream fs;
private long length;
private long downlength = 0;
private long lastlength = 0;
public delegate void updateData(string value); //设置委托用来更新主界面
private int totalseconds = 0; //总用时
private updateData UIDel;
private string filename = @"d:\sybaohj.wmv";
private int DownLoadNumber = 0; //文件下载计数
private void downloadFile()
{
ns = httpResponse.GetResponseStream();
int i;
UIDel = new updateData(updateUI);
while ((i = ns.Read(buffer, 0, buffer.Length)) > 0)
{
downlength += i;
string value = downlength.ToString();
this.Invoke(UIDel, value);
fs.Write(buffer, 0, i);
}
speedlabel1.Text = "下载完成";
}
/* private void show()
{
UIDel = new updateData(updateUI);
int value = 0;
while (value <= 100)
{
this.progressBar1.Value = value;
value++;
}
}*/
void updateUI(string value)
{
this.lensthlabel1.Text = "下载大小:"+value;
this.progressBar1.Value = Int32.Parse(value);
}
下载代码入下``崩溃就是系统无任何响应```也不会自动关闭会退出 |
|