c# - Model for Maintaining Collection Over Multiple Threads -


i have shared instance of list gets updated randomly various threads (objects added via threads). have timer executes on set interval removes records list based on set of criteria--specifically, if records older x minutes. finding system scales out , threads become more numerous, method cleans list randomly throw exceptions iterates it. presume due contention between list updates , removal of records. best way prevent exceptions put lock on shared instance iteration done? if so, negatives of doing so. if not, other options there?

i'm sure pretty basic question i'm new threading issues.

i don't think stated strong enough: have lock it. beware list not great collection object this, removing old items costs o(n^2). consider creating new list old 1 or using linkedlist.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -