You can change the value in an item in the collection. The error you get means that the item has been added or removed. I .: the collection itself has been changed, not an element within the collection. This is most likely caused by another thread adding or removing items to this collection.
You must lock the queue at the beginning of your method so that other threads do not modify the collection while accessing it. Or you can lock the collection before calling this method.
private bool extractWriteActions(out List<WriteChannel> channelWrites) { lock(tpotActionQueue) { channelWrites = new List<WriteChannel>(); foreach (TpotAction action in tpotActionQueue) { if (action is WriteChannel) { channelWrites.Add((WriteChannel)action); action.Status = RecordStatus.Batched; } } } return (channelWrites.Count > 0); }
source share