A
A
Anton_repr2020-05-14 11:18:50
C++ / C#
Anton_repr, 2020-05-14 11:18:50

How to use progress bar?

I made a YouTube video loader, but I can't get the progress bar to work.

progressBar1.Value = 0;
            await Task.Run(() =>
            {
                using (var service = Client.For(YouTube.Default))
                {
                    while (true)
                    {
                        var video = service.GetVideo(link_tb.Text);
                        string path = Path.Combine(save_tb.Text, video.FullName);
                        File.WriteAllBytes(path, video.GetBytes());
                    }
                }
            });

How to use the progress bar in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-05-15
@Anton_repr

// предполагается что ваш сервис скачивает асинхронно, и после скачивания части файла вызывает это событие
service.DownloadChunk += ChunkProcess;
private void ChunkProcess(object sender, int size)
{
    // обязательно проверьте в каком потоке обновляете UI
   // https://docs.microsoft.com/ru-ru/dotnet/framework/winforms/controls/how-to-make-thread-safe-calls-to-windows-forms-controls?view=netcore-3.1
    progressBar1.Value += size;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question