Truong Hong Thi wrote:
C# System.Collections.ArrayList provide similar functions, but is is
not thread-safe by default. To have thread-safe array list like
java.util.Vector, use ArrayList.Synchronized method:
ArrayList theVector = ArrayList.Synchronized(new ArrayList);
However, that model of thread-safety is pretty shallow anyway - you
can't safely iterate through a synchronized ArrayList (or Vector in
Java) without locking for the whole loop rather than just each bit of
the loop.
Personally I usually avoid the synchronized wrappers, explicitly
locking the SyncRoot property (or a private lock) if a collection needs
to be shared between threads.
Jon