Multiple tasks using Parallel Foreach and WhenAny. Is that possible?
<p>I want to scrape several websites at the same time, but just add the information to the database one by one. Meanwhile my code looks similar to this:</p>

<pre><code>        List&lt;SiteMetadata&gt; sitesList = GetSites();
        var tasks = new List&lt;Task&lt;SiteMetadata&gt;&gt;();

        foreach (var item in sitesList)
            tasks.Add(item.LoadMetaDataAsync());

        int totalSites = sitesList.Count;
        int finishedSites = 0;

        int errors = 0;
        while (totalSites != finishedSites)
        {
            var tempSite = await Task.WhenAny(tasks.ToArray());
            //WRITE HERE TO DB!!!!!!!!!!!!!!!!!
            tasks.Remove(tempSite);

            var tempLog = apiHandler.WriteToDatabase(tempSite.Result);

            if (tempLog.Type == LogType.Error)
            {
                errors++;
                LogsHandler.AddToLog(tempLog);
            }

            finishedSites++;
        }
</code></pre>

<p>I want is to increase the efficiency here and replace the:</p>

<pre><code>    var tasks = new List&lt;Task&lt;SiteMetadata&gt;&gt;();
    foreach (var item in sitesList)
        tasks.Add(item.LoadMetaDataAsync());
</code></pre>

<p>to something like this:</p>

<pre><code>    var runAll = Task.Factory.StartNew(() =&gt; Parallel.ForEach(sitesList, item =&gt; item.LoadMetaDataAsync()));
</code></pre>

<p>But the problem is that I dont know how to get the first task that finishes and to the database one by one. There is anyway to do this using the Parallel or something similar or even something more efficient than what I am doing right now?
Thanks in advance.</p>