I remember I saw a class with 2 exciting properties. I couldn't remember the class name but I think it was a collection, I'm not sure. The first property was named Read*word* and the second property was called Write*word*. Sadly I don't remember. Let me try to explain why these 2 properties exist. The idea was when a write happens we allow the already running "Reads" to finish but new ones will need to wait. See below how one would use this class.
var list = new ThreadSafeList();
// This is how we should read the collection.
using(var read = list.ReadLock)
{
// If a write is happening we will wait until it finishes.
await read.WaitAsync();
// Do something with the list. If we are here in the execution no writing can happen, only reads.
}
// This is how we should change the collection.
using(var write = list.WriteLock)
{
await write.WaitAsync();
// Modify the collection, nobody reads it, so we are safe.
}
Do I remember right? Is there a collection that has similar properties? If not can somebody tell me how I should make a similar class is this an AutoResetEvent or a ManualResetEvent maybe a Sempahore? I don't know.