zoukankan      html  css  js  c++  java
  • C# Download File Asynchronously from winform

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    
    namespace WindowsTreeViewDemo
    {
        /// <summary>
        /// 2011-06-25
        /// 涂聚文  QQ天气预报
        /// </summary>
        public partial class Form1 : Form
        {
            WebClient webClient = new WebClient();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button1_Click(object sender, EventArgs e)
            {
                
                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
                webClient.DownloadFileAsync(new Uri("http://weather.qq.com/inc/ss1.htm"), @"c:\201106021ss1.html");
    
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                progressBar1.Value = e.ProgressPercentage;
                this.label1.Text = "已完成:" + progressBar1.Value.ToString() + "%";
    
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void Completed(object sender, AsyncCompletedEventArgs e)
            {
                MessageBox.Show("Download completed!");
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button2_Click(object sender, EventArgs e)
            {
                //取消上传
                if (webClient != null)
                {
                    webClient.CancelAsync();
                }
                Close(); 
    
            }
    
    
        }
    }
    
    哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)
  • 相关阅读:
    NOIP2014飞扬的小鸟[DP][WRONG]
    POJ2184 Cow Exhibition[DP 状态负值]
    Quantum Bogo sort浅谈
    POJ3211 Washing Clothes[DP 分解 01背包可行性]
    VIJOS P1426兴奋剂检查[DP 状态哈希]
    VIJOS P1037搭建双塔[DP]
    NOIP2006金明的预算方案[DP 有依赖的背包问题]
    POJ1742 Coins[多重背包可行性]
    NOIP水题合集[3/未完待续]
    单调队列
  • 原文地址:https://www.cnblogs.com/geovindu/p/2090125.html
Copyright © 2011-2022 走看看