As the code shows below, I'm creating a thread in a foreach loop and running them at a later time, however when I run the thread I get the "object reference not set to an instance of an object" error. I suspect this is a closure problem, but it seems like i'm doing everything i should be to avoid that here by creating a local copy of the value. How can this code be corrected to accomplish the creation of a threads, then at a later time, allowing for the methods to be invoked (threads started)?
foreach (ObjWithDelegateToCreateTrdFrom item in queryResult)
{
// Capture object state
ObjWithDelegateToCreateTrdFrom capturedValue = item;
// Create thread from object
Thread thread = new Thread(() =>
{
capturedValue.Method.Invoke(capturedValue.paramsArray)
});
// Add thread to temp thread list
trdList.Add(thread);
}