微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

这是我的代码

        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 举报,一经查实,本站将立刻删除。