I think I had a similar exception when using a foreach
loop on a Collection where I tried to remove items from the Collection (or it may have been a List, I can’t remember). I ended up getting around it by using a for
loop. Perhaps try something like the following:
for (int i=0; i<tpotActionQueue.Count(); i++)
{
TpotAction action = tpotActionQueue.Dequeue();
if (action is WriteChannel)
{
channelWrites.Add((WriteChannel)action);
lock(tpotActionQueue)
{
action.Status = RecordStatus.Batched;
}
}
}