locked
How to DownloadMultiple Files with Webclient RRS feed

  • Question

  • Hi every 1 ..

     

    i am getting a problem when i iterate through an array of files that i have to download and the error is " Web Client doens't support Multiple IO operations " any solution for this problem ?

     

     

     

    for (int i = 0; i < FilesList.Length; i++)

    {

    uri =" ftp://abc.com//aa//"+ FilesListIdea.ToString();

    Uri address = new Uri(uri);

    webcl.DownloadProgressChanged += new DownloadProgressChangedEventHandler   (webcl_DownloadProgressChanged);

    webcl.DownloadFileCompleted += new AsyncCompletedEventHandler(webcl_DownloadFileCompleted);

    webcl.DownloadFileAsync(address, "C:\\" + FilesListIdea.ToString());

     

     while(webcl.isbusy)

     {

     

     }

     

    }

     

    as you have seen i have use a while loop to cope up with this problem but u know this shifts my application in busy state . plz help me tc

     

    Tuesday, June 12, 2007 10:17 AM

Answers

  • Creating an array of WebClient objects does work, but it seems inefficient. Using a while loop is the way I do it, but you should add the "Application.DoEvents();" call in the loop.

    while (client.IsBusy)
    {
         Application.DoEvents();
    }


    This will allow for the application to still process messages.
    Tuesday, June 12, 2007 3:10 PM

All replies

  • I had the same problem

    Here the trick i used, and It seems to be faster than the DownloadFile method
    i declare an array of webclient

    Its Vb.Net code but its the same in C#

    declaration of handlers are optional just if you want check the downloads progression


    Vb code


    'an array of webclient

    Dim downloader_client(TOTAL_FILE_TO_SAVE) As WebClient

    For idx = 0 To TOTAL_FILE_TO_SAVE - 1
    'construction du webclient

    downloader_client(idx) = New WebClient
    'définition d'un handler pr chaque webclient
    AddHandler downloader_client(idx).DownloadProgressChanged, AddressOf DownloadProgress
    AddHandler downloader_client(idx).DownloadFileCompleted, AddressOf DownloadCompleted
    'lance chaque téléchargement

    downloader_client(idx).DownloadFileAsync(url, location)

    Next

    End Sub



    Tuesday, June 12, 2007 12:36 PM
  • Creating an array of WebClient objects does work, but it seems inefficient. Using a while loop is the way I do it, but you should add the "Application.DoEvents();" call in the loop.

    while (client.IsBusy)
    {
         Application.DoEvents();
    }


    This will allow for the application to still process messages.
    Tuesday, June 12, 2007 3:10 PM
  • thanx dave it really worked .. Smile thanx bro ..
    Wednesday, June 13, 2007 12:11 PM