// Sample call : DownLoadFileInBackground4 ("http://www.contoso.com/logs/January.txt");
public static void DownLoadFileInBackground4(string address)
{
WebClient client = new WebClient();
Uri uri = new Uri(address);
// Specify a DownloadFileCompleted handler here...
// Specify a progress notification handler.
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback4);
client.DownloadFileAsync(uri, "serverdata.txt");
}
private static void DownloadProgressCallback4(object sender, DownloadProgressChangedEventArgs e)
{
// Displays the operation identifier, and the transfer progress.
Console.WriteLine("{0} downloaded {1} of {2} bytes. {3} % complete...",
(string)e.UserState,
e.BytesReceived,
e.TotalBytesToReceive,
e.ProgressPercentage);
}
C# WEBCLIENT 下载实时返回进度
最新推荐文章于 2024-08-04 03:02:35 发布