我有下面的代码,除了写出下载的状态外它正常工作。如何在C#控制台应用程序中正确写出下载状态?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void clear()
{
Thread.Sleep(1500);
Console.SetCursorPosition(0, 0);
}
static void Main(string[] args)
{
var client = new WebClient();
client.DownloadProgressChanged += (o, e) =>
{
Console.Write(e.ProgressPercentage + "% ");
clear();
};
client.DownloadFileAsync(new Uri("http://XXX"), "file");
Console.ReadKey();
}
}
}
随着代码的许多新的行会被插入和下载的状态不会被更新,并打印出来。
谢谢你,完美的解决方案。 – roll