Starting tasks in a dynamic way

Viewed 636

I have a List<someObject> and an extention method to someObject called Process.

Consider the following

private void processList(List<someObject> list)
{
  Task.Factory.StartNew(() =>{
    foreach(var instance in list)
    {
        instance.Process();
    }});
}

but I wanted multiple Tasks to work on the same list, to avoid locking I cloned the list and divided it into 2 lists, then started 2 separate Tasks to process, the speed has almost doubled.

I was wondering if there are built in things in .NET that could help me achieve such things in a dynamic way and with cleaner syntax?

1 Answers
Related