.NET WebClient tag property, or keeping track of downloads ?

Posted by GX on Stack Overflow See other posts from Stack Overflow or by GX
Published on 2010-03-08T00:20:24Z Indexed on 2010/03/08 0:30 UTC
Read the original article Hit count: 722

Filed under:
|
|

Hello,

I am trying to implement an Asynchronous file download from a web server using

  private void btnDownload_Click(object sender, EventArgs e)
        {
            WebClient webClient = new WebClient();
            webClient.Credentials = new NetworkCredential("test", "test");
            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            webClient.DownloadFileAsync(new Uri("ftp://2.1.1.1:17865/zaz.txt"), @"c:\myfile.txt");
        }

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

        private void Completed(object sender, AsyncCompletedEventArgs e)
        {

            MessageBox.Show("Download completed!");
        }

Now the download works fine, what I would like to know is the following: assuming that I will have more than 1 download at a time, what is the best way to keep track of each download and report progress separately ? I was looking for a tag property of the WebClient, but could not find one.

Thank you

© Stack Overflow or respective owner

Related posts about c#

Related posts about webclient