多线程下载, 下载的测试网址可以输入这个 http://www.youpaopao.com/apkdown/youpaopao.apk下载后可以在 默认D盘中找到下载的文件 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Threading;namespace DownLoadHttp3{  public partial class Form1 : Form  {    public Form1()    {      Control.CheckForIllegalCrossThreadCalls = false;      InitializeComponent();    }    private void Form1_Load(object sender, EventArgs e)    {      this.txtSrcAddress.Text = @"http://www.100-try.com/soft/v.rar";      this.txtTarAddress.Text = @"D:";    }    private void btnDown_Click(object sender, EventArgs e)    {      //加到一个线程里面是为了防止假死      Thread th = new Thread(new ThreadStart(this.DownLoad));      th.Start();    }    private void DownLoad()    {      this.numUpDown.Enabled = false;      this.btnDown.Enabled = false;      //url      string url = this.txtSrcAddress.Text.Trim();      //保存的路径      string dir = this.txtTarAddress.Text.Trim();      //线程数      int threadNums = (int)this.numUpDown.Value;      ThreadDownload down = new ThreadDownload(threadNums, url, dir);      down.StartDownLoad();      //进度条      this.statusBar_process.Maximum = (int)down.FileSize;      while (!down.IsComplete)      {        this.statusBar_process.Value = down.DownFileSize;      }      if (down.IsComplete)      {        this.numUpDown.Enabled = true;        this.btnDown.Enabled = true;      }    }  }}
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Threading;namespace DownLoadHttp3{  public partial class Form1 : Form  {    public Form1()    {      Control.CheckForIllegalCrossThreadCalls = false;      InitializeComponent();    }    private void Form1_Load(object sender, EventArgs e)    {      this.txtSrcAddress.Text = @"http://www.100-try.com/soft/v.rar";      this.txtTarAddress.Text = @"D:";    }    private void btnDown_Click(object sender, EventArgs e)    {      //加到一个线程里面是为了防止假死      Thread th = new Thread(new ThreadStart(this.DownLoad));      th.Start();    }    private void DownLoad()    {      this.numUpDown.Enabled = false;      this.btnDown.Enabled = false;      //url      string url = this.txtSrcAddress.Text.Trim();      //保存的路径      string dir = this.txtTarAddress.Text.Trim();      //线程数      int threadNums = (int)this.numUpDown.Value;      ThreadDownload down = new ThreadDownload(threadNums, url, dir);      down.StartDownLoad();      //进度条      this.statusBar_process.Maximum = (int)down.FileSize;      while (!down.IsComplete)      {        this.statusBar_process.Value = down.DownFileSize;      }      if (down.IsComplete)      {        this.numUpDown.Enabled = true;        this.btnDown.Enabled = true;      }    }  }}

 
  
					
				
评论