I’m using VB.NET.
I want to build a large List (Of MyClassOrStructure) that becomes static after its initial population.
I’m going to have multiple threads that need to iterate through this list to read data (no writing, inserting, or deleting)
Are there any very bad things that I need to keep an eye out for?
Thanks.
If you’re just reading, you’re fine. Each iterator will be independent of the others.
If you’ve ever wondered why the
IEnumerable<T>interface doesn’t directly haveMoveNext()andCurrent, but instead has to create anIEnumerator<T>instance, that’s why – the list itself doesn’t keep the “cursor” saying where the iterator is, it’s in theIEnumerator<T>. Sharing theIEnumerator<T>values between threads would almost certainly be a bad idea – but you’re very unlikely to do that accidentally. The natural way of iterating on several threads will have oneIEnumerator<T>per thread, which is safe (so long as you don’t modify the list).