Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:40:11+00:00 2026-05-28T16:40:11+00:00

foreach (string line in textBox3.Lines) { int pos = line.IndexOf(?v=); string videoid = line.Substring(pos

  • 0
                    foreach (string line in textBox3.Lines)
                    {
                        int pos = line.IndexOf("?v=");
                        string videoid = line.Substring(pos + 3, 11);
                        GetFile(videoid);
                    }

        GetFile() {
        ...code

        WebClient webClient = new WebClient();
        webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
        webClient.DownloadFileAsync(new Uri(fileRequest), @textBox2.Text + @"\" + title + ".mp3");
    }

    private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        progressBar1.Value = e.ProgressPercentage;
    }

Question is how to hadle one progressbar and many webclients? This scenario doesn’t work, because every client is updating bar on it’s own and it’s going crazy, so what’s the proper way? PS. I cannot use just one WebClient, I’m making requests before for every file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:40:12+00:00Added an answer on May 28, 2026 at 4:40 pm

    I’d imagine you could do something like this:

    public class WebClientProgressManager : INotifyPropertyChanged
            {
                private readonly Dictionary<WebClient,int> _clients = new Dictionary<WebClient, int>();
                private const string TotalProgressPropertyName = "TotalProgress";
                public void Add(WebClient client)
                {
                    if (client == null)
                        throw new ArgumentNullException("client");
                    if (_clients.ContainsKey(client)) return;
    
                    client.DownloadProgressChanged += (s, e) =>
                                                          {
                                                              if (e.ProgressPercentage == 100)
                                                              {
                                                                  _clients.Remove((WebClient)s);
                                                              }
                                                              RaisePropertyChanged(TotalProgressPropertyName);
                                                          };
                    _clients.Add(client,0);
    
                }
    
                private void RaisePropertyChanged(string propertyName)
                {
                    if (PropertyChanged != null)
                    {
                        PropertyChanged.Invoke(this,new PropertyChangedEventArgs(propertyName));
                    }
                }
    
                public int TotalProgress
                {
    
                    get
                    {
                        if (_clients.Count == 0) return 100; //need something here to prevent divide-by-zero 
                        int progress = _clients.Sum(client => client.Value);
                        return progress/_clients.Count;
                    }
                }
    
                #region Implementation of INotifyPropertyChanged
    
                public event PropertyChangedEventHandler PropertyChanged;
    
                #endregion
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here's my code: XmlDocument doc = new XmlDocument(); foreach (string c in colorList) {
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
var lines = File.ReadAllLines(filelocation); char[] space = { ',' }; string templine; foreach (string
foreach (string line in assigment_lines) { // Object reference not set to an instance
For Each line As String In System.IO.File.ReadAllLines(file.txt) 'Do Something' Next and Using f As
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Upload(Photo photo) { foreach (string file in Request.Files) { var path
I am adding checkboxes dynamically to silverlight stackpanel object as follows: foreach (String userName
How do I loop into all the resources in the resourcemanager? Ie: foreach (string
I see some people write: //wordList is List<string> wordList.ForEach(delegate(string word){ Console.WriteLine(word);}); instead of: foreach(string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.