tags:

views:

56

answers:

1

I am trying to process 2 independent tasks using the new .NET 4.0 Task Parallel Library

inputList1 is List<CustomObject>

inputList2 is List<DateTime>

List<double> firstCall = GetDoubleListing(inputList1, inputList2); 
List<double> secondCall = GetAnotherListing(inputList3, inputList2); 

inputList2 is common in both the calls ( it is a read only list ).

I tried to use the following code but kept getting exceptions

Task[] tsk = {
    Task<List<double>>.Factory.StartNew(GetDoubleListing(inputList1, inputList2)),
    Task<List<double>>.Factory.StartNew(GetAnotherListing(inputList3, inputList2));
};

Can someone guide me as to how to pass parameters and how to enable Task Parallel Library.

+3  A: 

It appears you just want the GetDoubleListing() and GetAnotherListing() calls done in parallel. The overloads for StartNew() require delegates. As the parameters are not changing, you can make the calls using lambdas like this:

Task[] tsk =
{
    Task<List<double>>.Factory.StartNew(() => GetDoubleListing(inputList1, inputList2)),
    Task<List<double>>.Factory.StartNew(() => GetAnotherListing(inputList3, inputList2));
};
Jeff M