C
C#2y ago
Thinker

✅ Thread-safe list

I'm trying to turn a piece of code which just calls a list of tasks asynchronous. Each of these tasks writes to a List<T> passed to all the tasks. I'm using Task.WhenAll to run all the tasks in parallel, however I'm unsure of whether using a regular List<T> is fine or if I should be using something else.
2 Replies
Pobiega
Pobiega2y ago
List is not threadsafe, so I'd be on the safe side and use something else
Thinker
ThinkerOP2y ago
Switched to ConcurrectBag<T> (because I don't need order) and it works fine

Did you find this page helpful?