基本信息
源码名称:C# 多线程下载文件(http,亲测通过)
源码大小:0.05M
文件格式:.rar
开发语言:C#
更新时间:2016-05-05
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 8 元×
微信扫码支付:8 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
多线程下载, 下载的测试网址可以输入这个 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;
}
}
}
}