title: C# Multiple progress bars for multiple file downloads
body: <p>I am writing a C# application for uploading and downloading file. The download uses WebClient object and its <code>DownloadAsycDownload</code> method. The download works fine for multiple files. It downloads as much files as I want. </p>
  
  <p>My problem is I am not able to show the progress of all file in different progress bars which are dynamically added to the form's <code>flowlayout control</code>. </p>
  
  <p><strong>Here is my code:</strong></p>
  
  <pre><code>public ProgressBar[] bar;
  public int countBar=0;
  
  ...
  
      bar[countBar] = new ProgressBar();
      flowLayoutPanel1.Controls.Add(bar[countBar]);
      countBar++;
  
      request.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownoadInProgress);
      request.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
      request.DownloadFileAsync(new Uri(this.uri), localPath);
  
      byte[] fileData = request.DownloadData(this.uri);
      FileStream file = File.Create(localPath);
      file.Write(fileData, 0, fileData.Length);
      file.Close();
  }
  
  public void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  {
      flowLayoutPanel1.Controls.Remove(bar[countBar]);
      countBar--;
      MessageBox.Show("Download Completed");
  }
  
  public void DownoadInProgress(object sender, DownloadProgressChangedEventArgs e)
  {
      bar[countBar].Maximum = total_bytes;
      bar[countBar].Value = (int)e.BytesReceived;                
  }
  </code></pre>