How to make WebClient wait until previous download is finished?
<p>I'm using <code>DownloadFileAsyncTask</code> method to download files. However, when i execute it in a loop i get an exception, which tells me concurrent operations are not supported. I tried to fix it like this:</p>

<pre><code>  public async Task&lt;string&gt; Download(string uri, string path)
    {
        if (uri == null) return;

        //manually wait for previous task to complete
        while (Client.IsBusy)
        {
            await Task.Delay(10);
        }

        await Client.DownloadFileTaskAsync(new Uri(absoluteUri), path);

        return path;
    }
</code></pre>

<p>Sometimes it works, when a number of iterations isn't big(1-5), and when it runs 10 or more times i'm getting this error.
 <code>Client</code> here is a <code>WebClient</code> and i create it once. I don't produce a new Clients on every iteration because it makes an overhead.
Back to i was saying, how to make <code>WebClient</code> wait before previous download finishes? Also a question here is why <code>IsBusy</code> works for small amount of downloads.
The code i'm using: </p>

<pre><code> public IEnumerable&lt;Task&lt;string&gt;&gt; GetPathById(IEnumerable&lt;Photo&gt; photos)
    {
        return photos?.Select(
                     async photo =&gt;
                     {
                         var path = await Download(Uri, Path);
                         return path;
                     });
    }
</code></pre>

<p>I want to download many files and don't block my Ui thread. Maybe there is other way to do this?</p>