I have 1.N threads writing to a .net 4.0 Concurren开发者_C百科tDictionary. I have another thread which fires every 5 seconds (settable in app.config) to enumerate the dictionary, and potentially remove some items. I want to halt the write operations during the enumeration.
What would be the best primitive to synchronize these two operations. Any help would be appreciated.
Bob.
use ReaderWriterLockSlim
(http://msdn.microsoft.com/library/system.threading.readerwriterlockslim(VS.90).aspx) so enumerating thread will request exclusive lock and writing threads non-exclusive.
精彩评论