1

I am implementing a windows form application in which we are taking url as input from multiline textbox and by using a loop we are downloading the files. In the download function I am implementing a webclient for downloading.

Using a loop creates too many Webclient requests .Now Since I have a single progressBar , it causes the progressbar to fluctuate. Here is an image of program.

enter image description here

I am looking for some method so that only one file is downloaded and causes other to pause for a while. This would cause progrressbar to work for one file only.

private void Download_Click(object sender, EventArgs e)
    {
        label1.Text = "Starting Download ... Please Wait ...";


        string[] sep = new string[] { "\r\n" };
        string[] lines = textBox1.Text.Split(sep, StringSplitOptions.RemoveEmptyEntries);
        for (int i = 0; i < lines.Length; i++)
        {
            download(lines[i]);
        }

    }


    private  void download(string song)
    {

        string name = song;

        song = query(song);
        using (webclient = new WebClient())
        {
            // ...statements
            using (client = new WebClient())
            {
                client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
                client.DownloadFileAsync(new Uri(DOWN_URL + download_url), @dest + "\\" + name + ".mp3");
            }
        }



    }

    private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
        count++;
        label1.Text = "Downloaded " + count.ToString() + " song(s)";
    }

    private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {

        progressBar1.Value = e.ProgressPercentage;
        label1.Text = "Downloading";
    }
Yash Bansal
  • 108
  • 1
  • 10

0 Answers0