L
L
LiptonOlolo2016-02-16 23:56:44
C++ / C#
LiptonOlolo, 2016-02-16 23:56:44

How to download multiple files through WebClient one by one? Via DownloadFileAsync?

Goodnight. Faced the problem of downloading several files one after another.
Full code how to download:

void DownloadMPQ(Uri u, string s)
        {
            WebClient web = new WebClient();
            web.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Download);
            web.DownloadFileCompleted += new AsyncCompletedEventHandler(DownComp);
            web.DownloadFileAsync(u, s);
        }
        void DownComp(object sender, AsyncCompletedEventArgs e)
        {
            NotificShow(String.Format("'{0}' скачан.", ThisFile));
        }
        void Download(object sender, DownloadProgressChangedEventArgs e)
        {
            long q = e.TotalBytesToReceive / 1024;
            prgDownload.Properties.Maximum = (int)q;
            prgDownload.EditValue = e.BytesReceived / 1024;
        }

And how I call (on the example of 1 file)
DownloadMPQ(new Uri("http://localhost/mp.mpq"), "mp.mpq");

As a result, he starts downloading all the files in a row to me, i.e. into multiple threads.
The question is still this: how can I wait for downloading 1 file and start downloading the 2nd one? New stream? Tried. The progress bar does not move.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2016-02-17
@Nipheris

1) immediately try DownloadFileTaskAsync , it is easier to work with tasks;
2) wait for the task to download one file to complete before starting the next one;
3)

New stream? Tried. The progress bar does not move.

Work with controls only from the GUI thread. Read about SynchronizationContext.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question