Partition TPL Tasks in ASP.NET 4.0 for WCF Service I would like to know if using partition code like this is ok to do to partition tasks in ASP.NET 4.0 inside of a WCF service.  My goal with this code is to try to do non-blocking calls without spinning up too many concurrent tasks on the server.

public static async Task&lt;IEnumerable&lt;string&gt;&gt; ExecuteTasks(IEnumerable&lt;string&gt; files)
    {
        ConcurrentBag&lt;string&gt; bag = new ConcurrentBag&lt;string&gt;();

        await Task.Factory.ContinueWhenAll(Partitioner.Create(files).GetPartitions(5).Select(partition =&gt; Task.Factory.StartNew(() =&gt;
       {
           using (partition)
           {
               while (partition.MoveNext())
               {
                    string test = string.Format("File {2} is executing in thread {0} and {3} in background at {1}", 
                                               Thread.CurrentThread.ManagedThreadId, 
                                                DateTime.Now, partition.Current, 
                                                Thread.CurrentThread.IsBackground);
                   Console.WriteLine(test);
                   bag.Add(test);
               }
           }
        }, TaskCreationOptions.LongRunning)).ToArray(), _ =&gt; { });

        return bag.ToList();
    }
Specification

There are a couple of strategies available to you depending on what exactly you mean with 


  "not spinning up too many concurrent tasks"


Possible Strategies


If you want a maximum allowed number of tasks to be processed concurrently on the server, regardless of this method, assuming you are using the default task scheduler, you can set the maximum number of threads of the .NET ThreadPool.
If you want a maximum allowed number of tasks to be processed concurrently for this given scenario, leaving the other task scheduling on the server alone, you can:


implement a custom TaskScheduler with its own dedicated thread pool. In .NET Framework you might also implement a custom SynchronizationContext instead. It's a lower level than the scheduler and you can always create a TaskScheduler.FromCurrentSynchronizationContext();.
use a SemaphoreSlim to limit the number of tasks that actually perform work concurrently. Note that this could still lead to more threads than your threshold to be activated, however, only the specified threshold amount of threads would actually be performing work.
Use JanDotNet's Parallel with MaxDegreeOfParallelism approach within a single Task. Note that this changes the affinity from threads to processors. Not sure whether this is what you are looking for. But at least it's a possibility, and non-blocking because wrapped inside a Task.