Hello everyone,
I am attempting at embedding multi-threading for the first time ever and running into some unexpected issues, hope you can help.
Here's the code fragment that gives me troubles:
ArrayList recordsCollection = new ArrayList();
ArrayList batchCollection = null;
int idx = 0;
while(true)
{
// Some code to generate and assign new batchCollection here
recordsCollection.Add(batchCollection);
ThreadPool.QueueUserWorkItem(delegate
{
ProcessCollection(recordsCollection.GetRange(idx, 1));
});
Interlocked.Increment(ref idx);
}
private void ProcessCollection(ArrayList collection)
{
// Do some work on collection here
}
Once the Process Collection method is invoked and I am attempting to iterate through collection I am getting "The range in the underlying list is invalid".
Thanks in advance!
Update: Guys, thank you to each and every one of you. Through applying your suggestions I was able to greatly simplify and get it to work.