C
C#15mo 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
Pobiega15mo ago
List is not threadsafe, so I'd be on the safe side and use something else
Thinker
Thinker15mo ago
Switched to ConcurrectBag<T> (because I don't need order) and it works fine