© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
Jason

Restart method with fresh list to iterate through without triggering 'collection was modified' error

I've provided a pseudo code version of the problem. This normally wouldn't be a problem as I could just remove the code that modifies the list, however I want this operation to work automatically without my input / manual intervention. What can I add to this code to make that happen? I considered adding cancellation tokens but that would only cancel the current task, it wouldn't take the program out of the current iteration (inside this try catch block).
screen.jpg
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Iterate through a genereic type list
C#CC# / help
3y ago
Iterate through Enums
C#CC# / help
15mo ago
Collection was modified. Enumeration operation may not execute.
C#CC# / help
15mo ago
Collection was modified enumeration operation may not execute
C#CC# / help
4y ago