I have a bit of code that works like this on a list of obj objects called ListofObjects:
List NewListofObjects();
Parall
You can use the locking block like the following code to insert items into your list in a thread-safe manner.
var sync = new object();
var myNewList = new List();
Parallel.ForEach(myListOfSomethings, a =>
{
// Some other code...
var someObj = new SomeObject();
// More other code...
lock(sync)
{
myNewList.Add(someObj);
}
// Even more code...
});