zoukankan      html  css  js  c++  java
  • WebClient异步下载文件


    namespace ConsoleAppSyncDownload
    {
        class Program
        {

            static void Main(string[] args)
            {
                WebClient webClient = new WebClient();
                //Console.Write("输入下载文件地址:");
                //var s = Console.ReadLine();
                Console.WriteLine("是否开始下载(Y/N)");
                if (Console.ReadLine() == "Y")
                {
                    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
                    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);

                    webClient.DownloadFileAsync(new Uri("http://cd001.www.duba.net/duba/install/2011/ever/kavsetup140818_99_50.exe"), "0818_99_50.exe");

                }
                Console.Read();
            }

            private static void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
            {
                if (e.Cancelled)
                {
                    Console.WriteLine("下载被取消");
                }
                else
                {
                    Console.WriteLine("下载完成");
                }
            }

            private static void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
              
                Console.WriteLine(string.Format("正在下载文件,完成进度{0}/{1}(字节){2}",
                    e.BytesReceived, e.TotalBytesToReceive,e.ProgressPercentage.ToString() + "%"));
            }
        }
    }

    WebClient

  • 相关阅读:
    Bayes分类器原理分析以及实现
    数据库视图探究
    请求页式存储管理系统实验
    离散数学知识点整理(一)
    数据结构知识点总结之树
    数据结构知识点总结之栈、队列
    数据结构知识点总结之串、数组、广义表
    数据结构知识点总结之线性表
    数据结构知识点总结之绪论
    数据结构知识点总结
  • 原文地址:https://www.cnblogs.com/liucyi/p/3933665.html
Copyright © 2011-2022 走看看