如何制作通过命令行下载文件的进度条?

问题描述

这是我的代码

        static void Main(string[] args)
        {
            Console.WriteLine("Choose where to install. The files will be temporarily held in the C: drive.");
            var InstallDir = Console.ReadLine();
            using (var client = new WebClient())
            {
                Directory.CreateDirectory(@"C:\Users\Public\Planetary");
                Console.WriteLine("Now downloading. Don't close the window!");
                Uri uri = new Uri(""); // Not giving the URL link

                client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);

                client.DownloadFileAsync(uri,@"C:\Users\Public\Planetary\ExampleFile.exe");
                Directory.SetCurrentDirectory(@"C:\Users\Public\Planetary");
                Console.WriteLine("Download complete. Installing...");
                Process.Start(@"ExampleFile.exe",@"/VERYSILENT /DIR=" + (char)34 + InstallDir + (char)34);
            }
        }

        private static void DownloadProgressCallback(object sender,DownloadProgressChangedEventArgs e)
        {

            Console.WriteLine("{0}    downloaded {1} of {2} bytes. {3} % complete...",(string)e.UserState,e.BytesReceived,e.TotalBytesToReceive,e.Progresspercentage);
        }

我遇到了一个问题,它会尝试下载文件,什么也不做,然后尝试打开 ExampleFile.exe(尚不存在)。如果您需要,我正在使用控制台应用程序 (.NET Framework)。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)