Multiple thread working with one collection

  • Thread starter Thread starter Martin Zugec
  • Start date Start date
M

Martin Zugec

Heya,

I have application that is updating few collections from few (about 5)
different threads. Just wanted to ask if anyone can point me to any
documentation\best practices site where this is described?

I would like to implement it correctly...

Martin
 
Martin Zugec said:
I have application that is updating few collections from few (about 5)
different threads. Just wanted to ask if anyone can point me to any
documentation\best practices site where this is described?

You'll have to synchronize access to the shared resource. To do so, you can
use the 'SyncLock' statement and/or the 'Monitor' class, for example. Note
that you have to synchronize both read and write access to the collection
and maybe the objects contained in the collection.
 
Hi Herfried,

yes, I know this, but I would like to see some real life example...
Due to fact that you must lock collections even for read, I
implemented code that create copy of array, unlocks it, then it
perform some tasks (check revision numbers for example) and if it
detects any changes\problem, then it locks it again and check if it is
still reasonable to perform changes on parent...

Otherwise some not-that-important thread (for example checking if
there is new entry, which happens only once every few days) would lock
my collection for thread where almost real-time reaction is needed :(

It would be nice to have some complex project available in VB.NET to
see how interaction between different threads with different
priorities is implemented :(
 
Back
Top