WebClient,DownloadFileAsync,DownloadProgressChanged

static void Main(string[] args)
        {
            WebClientDownloadProgressChanged();
            Console.ReadLine();
        }

        static void WebClientDownloadProgressChanged()
        {
            string url = "https://download.microsoft.com/download/d/1/c/d1c74788-0c6b-4d23-896e-67cf849d31ed/SSMS-Setup-ENU.exe";
            using(WebClient wc=new WebClient())
            {
                wc.DownloadProgressChanged += Wc_DownloadProgressChanged1;
                wc.DownloadFileAsync(new Uri(url), "ssms.exe");
            }
        }

        private static void Wc_DownloadProgressChanged1(object sender, DownloadProgressChangedEventArgs e)
        {
            Console.WriteLine($"TotalBytesToReceive:{e.TotalBytesToReceive},BytesReceived:{e.BytesReceived},ProgressPercentage:{e.ProgressPercentage}");
        }

 

posted @ 2020-07-20 11:01  FredGrit  阅读(394)  评论(0编辑  收藏  举报