Iterate an array of BlockingCollections I have an array of BlockingCollections that i have initiated like this:

BlockingCollection&lt;FxDataMapper&gt;[] _fxDataByPair ;
arrayOfBlockingCollection = new BlockingCollection&lt;MyClassInstance&gt;[4];
            for (int i = 0; i &lt; 4; i++)
                _arrayOfBlockingCollection[i] = new BlockingCollection&lt;MyClassInstance&gt;();


Now it want to iterate the array and extract each of the array elements and consume the BlockingCollections elements My code is this and although it works i think its not the best one

private void testArrayConsuming()
{
    Task processor = Task.Factory.StartNew(() =&gt;
    {
        foreach (var x in arrayOfBlockingCollection )
        {
            Task processor2 = Task.Factory.StartNew(() =&gt;
            {
                foreach (var y in x.GetConsumingEnumerable())
                        Console.WriteLine(x.Element.Value.ToString());

            });
        }
    });
}
Your code has a couple of problems:


It is a void (synchronous) whose only task is to start a Task, lying to the caller since it's in fact an asynchronous Task.
You are using Task.Factory.StartNew instead of the preferred Task.Run


So, a better approach to this would be something like this:

private async Task testArrayConsuming()
{
    foreach (var x in arrayOfBlockingCollection)
    {
        await Task.Run(() =&gt;
        {
            foreach (var y in x.GetConsumingEnumerable())
            {
                Console.WriteLine(x.Element.Value.ToString());
            }
        });
    }
}


This would block execution, consuming one x at a time. If you want this to be parallel, use this instead:

private async Task testArrayConsuming()
{
    var tasks = new List&lt;Task&gt;();
    foreach (var x in arrayOfBlockingCollection)
    {
        tasks.Add(Task.Run(() =&gt;
        {
            foreach (var y in x.GetConsumingEnumerable())
            {
                Console.WriteLine(x.Element.Value.ToString());
            }
        }));
    }

    await Task.WhenAll(tasks); // wait for all of them
}