The app downloading multiple files asynchronously, so when i enter 10 links into listbox 10 files start to download. I wast to create progress bars dynamically for every file and report progress. This is what im using to report progress
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(worker_ProgressChanged);
but its not working.
When i do
worker.ReportProgress(10);
it works but im can only report an integer and not client.DownloadProgressChanged.
My question is how do i attach client.DownloadProgressChanged to my worker_ProgressChanged class.
What I have tried:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
List<string> myList = (List<string>)e.Argument;
foreach(string yo in myList)
{
ProgressBar bar = new ProgressBar();
position += 30;
bar.Width = 300;
bar.Location = new Point(300, position);
Invoke(new ToDoDelegate(() => bar.Location = new Point(150, position)));
Invoke(new ToDoDelegate(() => this.Controls.Add(bar)));
Invoke(new ToDoDelegate(() => bar.Visible = true));
WebClient client = new WebClient();
string FileName = yo.Substring(yo.LastIndexOf("/") + 1, (yo.Length - yo.LastIndexOf("/") - 1));
client.DownloadFileAsync(new Uri(yo), "C:\\Test4\\" + FileName);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(worker_ProgressChanged);
// (sender as BackgroundWorker).ReportProgress((client.DownloadFileAsync( new Uri(yo), FileName)));
worker.ReportProgress(10);
}
}
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
MessageBox.Show("I am reporting");
}