1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using System.Net;
  8. using System.IO;
  9. using System.Windows.Forms;
  10.  
  11. namespace ConsoleApp392
  12. {
  13. class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. WebClientDownloadDemo();
  18. }
  19.  
  20. static void WebClientDownloadDemo()
  21. {
  22. string url = "https://go.microsoft.com/fwlink/?linkid=866662";
  23. WebClient webClient = new WebClient();
  24. webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
  25. webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
  26. Console.WriteLine($"Started at {DateTime.Now.ToString("yyyyMMddHHmmssffff")}");
  27. webClient.DownloadFileAsync(new Uri(url), "SSMS2019.exe");
  28. }
  29.  
  30. private static void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
  31. {
  32. MessageBox.Show("Download Completed!");
  33. }
  34.  
  35. private static void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  36. {
  37. Debug.WriteLine($"{e.UserState?.ToString()} downloaded {e.BytesReceived} of {e.TotalBytesToReceive} bytes. {e.ProgressPercentage} % complete...");
  38. Console.WriteLine($"{e.UserState?.ToString()} downloaded {e.BytesReceived} of {e.TotalBytesToReceive} bytes. {e.ProgressPercentage} % complete...");
  39. }
  40. }
  41. }

C# webclient progresschanged downlodfileCompleted的更多相关文章

  1. 跨域请求——WebClient通过get和post请求api

    AJAX不可以实现跨域请求,经过特殊处理才行.一般后台可以通过WebClient实现跨域请求~ //get 请求        string url = string.Format("htt ...

  2. C#通过WebClient/HttpWebRequest实现http的post/get方法

    C#通过WebClient/HttpWebRequest实现http的post/get方法 http://www.cnblogs.com/shadowtale/p/3372735.html

  3. WebClient 实现多文件/文本同时上传

    public class CreateBytes { Encoding encoding = Encoding.UTF8; /**/ /// <summary> /// 拼接所有的二进制数 ...

  4. WebClient 数据传输

    数据提交 post  ,get public string WebClientPost(string PostData, string PostUrl, string Type) { string p ...

  5. C# 文件下载 : WebClient

    最近更新了一个下载小工具,主要提升了下面几点: 1. 在一些分公司的局域网中,连接不上外网 2. 服务器上的文件更新后,下载到的还是更新前的文件 3. 没有下载进度提示 4. 不能终止下载 下面和大家 ...

  6. C# 发送Http请求 - WebClient类

    WebClient位于System.Net命名空间下,通过这个类可以方便的创建Http请求并获取返回内容. 一.用法1 - DownloadData string uri = "http:/ ...

  7. c# WebClient Get Post 方法

    public string GetData(string url) { string data; using (var client = new WebClient()) { using (var s ...

  8. c# WebClient文件下载

    public void HttpDownload(string url, string path, ResourceType type) { using (var client = new WebCl ...

  9. [解决WebClient或HttpWebRequest首次连接缓慢问题]

    [编程环境]Visual Studio 2010, NET4.0 [开发语言]C#, 理论上VB.NET等依赖.NET Framework框架的语言均受此影响 [问题描述] 使用HttpWebRequ ...

随机推荐

  1. 安装lispbox出现:error while loading shared libraries: libjpeg.so.62: cannot open shared object file: No such file or directory

    如下图,运行lispbox出现如下报错(第一个命令): 检索之后发现解决办法:Solution to libjpeg.so.62 输入一下两条命令(第二条也必须执行): sudo apt-get up ...

  2. 获取本地计算机名称和Ip地址

    using System.Net; Dns.GetHostName();//获取本地计算机主机名 IPAddress[] IP = Dns.GetHostAddresses(Dns.GetHostNa ...

  3. Docker 以及 docker-compose 的部署

    Docker部署 方式一 #下载软件源 wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.ustc.edu.cn/docker-ce/li ...

  4. 【Python进阶】来谈谈几个常用的内置函数

    匿名函数(lambda表达式) 在Python中,函数可以算的上是“一等公民”了,我们先回顾下函数的优点: 减少代码重复量 模块化代码 但是我们有没有想过,如果我们需要一个函数,比较简短,而且只需要使 ...

  5. 软件开发工具(第11章:Eclipse CDT开发常用功能)

    一.自定义编辑器 C/C++首选项设置(重点.记忆.应用) 单击菜单栏中的窗口(Window)菜单, 选择首选项(Preferences)选项,在 弹出的对话框左侧部分,展开C/C++树 形菜单. 外 ...

  6. React路由的使用 Redirect默认展示某一个页面 Switch找到停止 BrowserRouter和HashRouter 的区别

    引入 Redirect 默认展示某一个页面 Switch 一旦找到 路由 就停止 不会在往下找了 App.js import {Link,Route,NavLink,Redirect,Switch} ...

  7. ASP.NET Core身份验证

    asp.net core 身份验证 本文旨在演示如果使用内置的 identity 实现 asp.net core 的身份验证,不会进行其它扩展.本文将通过最简单的代码演示如何进行登录和身份验证操作. ...

  8. vue element之axios下载文件(后端Python)

    axios 接受文件流,需要设置 {responseType:'arraybuffer'} axios.post( apiUrl, formdata, {responseType:'arraybuff ...

  9. GO基础之接口

    一.概念1. 面向对象语言中,接口用于定义对象的行为.接口只指定对象应该做什么,实现这种行为的方法(实现细节)是由对象来决定.2. 在Go语言中,接口是一组方法签名. •接口只指定了类型应该具有的方法 ...

  10. 搭建ES集群

    服务版本选择 TEG的ctsdb当前最高版本采用的是es的6.4.3版本,为了日后与ctsdb衔接方便,部署开源版es时也采用该版本.6.4.3版本的es依赖的jdk版本要求在8u181以上,测试环境 ...