In a multithreaded application. I have a bunch of function that loop through a collection to read the information. I also have a bunch of function that modifies that same collection.
I’m looking for a way to isolate all the read and the write together. I don’t want a write to be done while a read is in progress. I was thinking of using SyncLock on the collection object but this will block multiple read trying to work in parallel.
Have you considered ReaderWriterLockSlim? You might want to check that using it is faster than a simple Monitor lock though. Do not consider the older ReaderWriterLock. Here’s what Jeffrey Richter has to say about it: