winform 下载
方法一:
WebClient webClint = new WebClient();
webClint.DownloadFile(下载文件的路径,下载到本地的地址);
方法二:异步
WebClient webClint;
float maxSpeed = 0;
float currentSpeed = 0;
float lastSpeed = 0;
long lastReceive = 0;
long reeciveSpan;
TimeSpan span;
DateTime start;
DateTime lastTime;
TimeSpan useTime;
protected void Button1_Click(object sender, EventArgs e)
{
webClint.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClint_DownloadProgressChanged);
webClint.DownloadFileAsync(new Uri下载文件的路径, 下载到本地的地址);
}
void webClint_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
span = DateTime.Now - lastTime;
lastTime = DateTime.Now;
useTime = lastTime - start;
reeciveSpan = e.BytesReceived - lastReceive;
currentSpeed = reeciveSpan * 1000 / (span.Milliseconds + 1) / 1024;
maxSpeed = currentSpeed > maxSpeed ? currentSpeed : maxSpeed;
lastSpeed = currentSpeed;
lastReceive = e.BytesReceived;
// progressBar1.Value = e.ProgressPercentage;
this.Label1.Text = "已下载: " + e.BytesReceived / 1024 + "KB\n" +
"总大小: " + e.TotalBytesToReceive / 1024 + "KB\n" +
"百分比: " + e.ProgressPercentage + "%\n" +
"当前速度: " + currentSpeed.ToString("F2") + "KB/s\n" +
"大速度: " + maxSpeed.ToString("F2") + "KB/s\n" +
"用时: " + (useTime.Minutes * 60 + useTime.Seconds) + "s";
if (e.BytesReceived == e.TotalBytesToReceive)
{
webClint.DownloadProgressChanged -= webClint_DownloadProgressChanged;
webClint.Dispose();
Response.Write("任务完成!");
webClint.Dispose();
//if (MessageBox.Show("是否关闭当前程序而立即安装?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
//{
// xiazai();
//}
}
}
winform 下载的更多相关文章
- winform下载网页源码
public partial class Form1 : Form{public Form1(){InitializeComponent();} private void button1_Click( ...
- C# Winform下载文件并显示进度条
private void btnDown_Click(object sender, EventArgs e) { DownloadFile("http://localhost:1928/We ...
- winform下载网页代码
1:webClient client=new WebClient(); client.Downloadstring(地址) client.Downloadfile(地址,保存路径) 2:后台线程dow ...
- Winform 下载服务器安装包并安装
代码中包含了检测本地安装盘符代码 一,定义下载委托事件(用于实现前台进度条更新和下载完成后事件的回调): private delegate void Action(); private string ...
- Winform下载文件并显示进度条
本来是要研究怎样判断下载完成,结果找到这个方法,可以在这个方法完成之后提示下载完成. 代码如下: using System; using System.Collections.Generic; usi ...
- winform 下载文件显示进度和百分比
/// <summary> /// 下载完成 /// </summary> private void DownloadFileCompleted() { IsComlate = ...
- 个人收藏--未整理—C# 上传下载文件
Winform下载文件 /// <summary> /// 下载文件 /// </summary> /// <param name="URL"> ...
- ssential Diagram for Windows FormsC#/winForm类似visio的拓扑图节点连线控件免费下载
Essential Diagram for Windows Forms是一款可扩展的.高性能的.NET平台下的拓扑图控件,可用于开发像Microsoft Visio一样的交互式地绘图和图解应用程序,在 ...
- SNF开发平台WinForm之六-上传下载组件使用-SNF快速开发平台3.3-Spring.Net.Framework
6.1运行效果: 6.2开发实现: 1.先在要使用的项目进行引用,SNF.WinForm.Attachments.dll文件. 2.在工具箱内新建选项卡->选择项,浏览找到文件SNF.WinFo ...
随机推荐
- Linux基础命令---lpr打印文件
lpr lpr指令用来打印文件,如果没有指定文件名,那么从标准输入读取内容.CUPS提供了许多设置默认目标的方法.首先查询“LPDEST”和“PRINTER”环境变量.如果没有设置,则使用lpopti ...
- Javascript 面向对象编程2:构造函数的继承
这个系列的第一部分,主要介绍了如何"封装"数据和方法,以及如何从原型对象生成实例.对象之间的"继承"的五种方法.比如,现在有一个"动物"对象 ...
- java ==与equals()方法的总结
1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boolean 他们之间的比较,应用双等号(==),比较的是他们的值. 2.复合数据 ...
- GitHub linux 提交文件及403错误处理
$git clone "Clone with HTTPS(自己生成的地址,如:https://github.com/******(用户名)/test.git)" 这时在你git ...
- Docker Swarm 配置文件存储
Docker Swarm 配置文件存储 config:宿主级容器服务配置文件单独保存到docker中存储调用. 环境: 系统:Centos 7.4 x64 应用版本:Docker 18.09.0 管理 ...
- Python sqlalchemy orm 多对多外键关联
多对多外键关联 注:使用三张表进行对应关联 实现代码: # 创建3个表 配置外键关联 # 调用Column创建字段 加类型 from sqlalchemy import Table, Column, ...
- 【Alpha】Scrum Meeting 2
前言 第2次会议在3月28日由PM在教一317召开. 主要确定了项目方向和目标功能,进行了任务分工.时长60min. 任务分配 姓名 当前阶段任务 下阶段任务 吴昊 熟悉代码和配置环境,发布手机端博客 ...
- topcoder srm 565 div1
problem1 link $f[i][j]$表示经过前$i$个怪物之后,花费$j$个硬币可以得到的最大值. problem2 link 设$nim[i]$表示数字$i$的nim值.那么题目就是求有多 ...
- Excel 表格查找重复数据,去重复统计
找出表格是否有重复数据: =IF(AND(G20=G19,D20=D19),"是","否") 筛选移除[重复的数据]然后开始统计 =SUBTOTAL(9,E2: ...
- spring boot2+jpa+thymeleaf增删改查例子
参考这遍文章做了一个例子,稍微不同之处,原文是spring boot.mysql,这里改成了spring boot 2.Oracle. 一.pom.xml引入相关模块web.jpa.thymeleaf ...