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 ...
随机推荐
- flutter 常用插件
audio_recorder: any #录音.播放 flutter_sound: ^1.1.5#录音 dropdown_menu: ^1.1.0#下拉菜单 simple_permissions:#权 ...
- Docker Swarm 高可用详解
Docker Swarm 高可用详解 Manager管理节点宕机后其他管理节点仍然可以使用管理 intermal distributed state store:内部分布式状态存储同步共享到每个节点. ...
- git 分支命名规范
为规范开发,保持代码提交记录以及 git 分支结构清晰,方便后续维护,现规范 git 的相关操作. 主要规范两点: git 分支命名规范 git 提交记录规范 1. git 分支命名规范 git 分支 ...
- IDEA设置(含永久破解IDEA)
永久破解IDEA(很多license服务器都是非永久性的,太麻烦了) https://www.cnblogs.com/iathanasy/p/9469280.html,亲测. 在我们为 IDEA 等编 ...
- 剑指offer(40)数组中只出现一次的数字
题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. 题目分析 第一种方法:使用js中的indexOf()和lastIndexOf(),只要两个相等, ...
- 在VS2013 使用C语言库函数,出现出现错误,提示使用不安全函数use _CRT_SECURE_NO_WARNINGS
在VS 2013 中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may ...
- Go 使用 JSON
Encode 将一个对象编码成 JSON 数据,接受一个 interface{} 对象,返回 []byte 和 err func Marshal(v interface{}) {[]byte,err} ...
- idea maven列表有问题的
idea maven列表有问题的,覆盖 C:\Users\用户名\.IntelliJIdea2017.2\system\Maven\Indices路径大致在这里 文件为 Indices.rar ...
- C# Array 基本数据类型数组的基类 传参问题
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- React项目中实现右键自定义菜单
最近在react项目中需要实现一个,右键自定义菜单功能.找了找发现纯react项目里没有什么工具可以实现这样的功能,所以在网上搜了搜相关资料.下面我会附上完整的组件代码. (注:以下代码非本人原创,具 ...