I have the following code:
lock (fullEventList)
{
ftl = fullEventList.Where(a => a != null)
.OrderBy(a => a.Start)
.ThenBy(a => a.TaskID)
.ThenBy(a => a.Status).ToList();
}
An exception (collection was modified) is being thrown which highlights the .OrderBy part of the line. Given there is a lock around the List fullEventList, I think there may be another thread somewhere modifying the list. There are some usages of .Sort() which modifies the list rather than returning a new list, but I've not found where that is occurring yet.
Is there a way to protect this line from the list being modified elsewhere?