使用 C# 在 ProgressBar 中显示下载进度

Show download progress in a ProgressBar with C#

我正在编写代码以从 YouTube 下载视频 我正在使用 videolibrary 来做到这一点。如何使用 C# 将下载任务与 ProgressBar 连接?

这是我目前的代码:

private async void buttondownload_Click(object sender, EventArgs e)
{
    try
    {
        using (FolderBrowserDialog fbd = new FolderBrowserDialog() { Description = "select your path ." })
        {
            if (fbd.ShowDialog() == DialogResult.OK)
            {                        
                var youtube = YouTube.Default;
                labelstatus.Text = "Downloading....";
                var video = await youtube.GetVideoAsync(textBoxurl.Text);
                //setting progress bar...............................??????

                File.WriteAllBytes(fbd.SelectedPath + video.FullName, await video.GetBytesAsync());
                labelstatus.Text = "Completed!";
            }
        }
    }

视频库不支持进度更改 但它在 YoutubeExtractor 请参阅下面的代码片段

Thread youtubeDownloader = new Thread(delegate () 
        {

            FolderBrowserDialog b = new FolderBrowserDialog();

            this.Invoke((MethodInvoker)delegate () { if (b.ShowDialog() != DialogResult.OK) return;  });
                {
                    string link = textBox1.Text;
                    IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);
                    VideoInfo video = videoInfos
                        .First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);
                    if (video.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(video);
                    }

                    var videoDownloader = new VideoDownloader(video, b.SelectedPath + video.Title);
                    videoDownloader.DownloadProgressChanged += (sender1, args) => this.Invoke((MethodInvoker)delegate () { progressBar1.Value = (int)args.ProgressPercentage;});
                    videoDownloader.Execute();
                }

        });
        youtubeDownloader.IsBackground = true;
        youtubeDownloader.Start();