Namespace Consoleappsyncdownload
{
Class Program
{
static void Main (string[] args)
{
WebClient WebClient = new WebClient ();
Console.Write ("Enter the download file address:");
var s = console.readline ();
Console.WriteLine ("Whether to start downloading (y/n)");
if (console.readline () = = "Y")
{
Webclient.downloadprogresschanged + = new Downloadprogresschangedeventhandler (webclient_downloadprogresschanged);
webclient.downloadfilecompleted + = new Asynccompletedeventhandler (webclient_downloadfilecompleted);
Webclient.downloadfileasync (The 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 ("Download Cancelled");
}
Else
{
Console.WriteLine ("Download Complete");
}
}
private static void Webclient_downloadprogresschanged (object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine (String. Format ("Downloading file, completing progress {0}/{1} (bytes) {2}",
E.bytesreceived, e.totalbytestoreceive,e.progresspercentage.tostring () + "%"));
}
}
}
WebClient
WebClient asynchronous Download file