I am attempting to use the Task Parallel Library to build a Matrix cell by cell.
I have the following code that does this:
List<Campaign> campaigns = GetHomeCampaigns();
Dictionary<int, string> sellers = GetHomeSellers();
int numTasks = campaigns.Count*sellers.Count;
Task<MatrixCell<string>>[] statusTasks = new Task<MatrixCell<string>>[numTasks];
int count = 0;
for(int i = 0; i < campaigns.Count -1;i++)
{
for(int j = 0; j < sellers.Count -1;j++)
{
Func<MatrixCell<string>> getStatus = () => GetStatus(campaigns[i].CampaignID, sellers.ElementAt(j).Key);
statusTasks[count] = Task.Factory.StartNew(getStatus);
count++;
}
}
Task.WaitAll(statusTasks);
What I am attempting to do is to process and determine each cell in parallel, and then once they are all completed, assemble the Matrix row by row with additional code that is not relevant to this example.
The problem I am facing right now is for the following line
Task.WaitAll(statusTasks)
I am getting the following ArgumentException
The tasks array included at least one null element.
Parameter name: tasks
I have checked the array, and it shows all the items are present in statusTasks.
Not sure quite where else to look.
Thanks,