I have a method that accepts a List<int>
called DoWork
. I have a huge List<int> Ids
. I split the huge list into 4 sub lists:
List<List<int>> t = (List<List<int>>)SplitColumn<int>(Ids);
(SplitColumn
is slightly modified from the answer to splitting a list into sub lists).
I paused the program and inspected t
with the debugger and it is four lists divided exactly as I would expect.
Then, what I'm trying to do is spawn four threads (one for each sublist). The part I'm having trouble with is passing the four lists. I am getting out of bounds problems, I'm not sure what's going on here:
List<Thread> threads = new List<Thread>();
for(int i = 0; i < t.Count; i++)
{
threads.Add(new Thread(() => DoWork(t[i])));
}
foreach (Thread thread in threads)
{
thread.Start();
}
foreach (Thread thread in threads)
{
thread.Join();
}