Question: Is this right way to use AsyncReaderWriterLock ?

Example:

```
 private readonly static AsyncReaderWriterLock rwlMyClass = new AsyncReaderWriterLock();
 private List<MyClass> my = new List<MyClass>();

public List<MyClass> My
        {
            get
            {
                using (rwlMyClass.ReaderLock())
                {
                    return my;
                }
            }
        }

```

No i'm not sure what is better:

```
    try
            {
List<MyClass> my2 = await this.Exchange.GetDataAsync(); // Take 5s
                using (await rwlMyClass.WriterLockAsync())
                {
                    this.my = my2;
                }

        }

```

or this, i think above is better, because lock is only on quick action

```
 using (await rwlMyClass.WriterLockAsync())
                {
                    this.my = await this.Exchange.GetDataAsync();
                }

```

is always better, make clone of collection, make changes and only lock transfer to property ?
Thank you.

Answer: 
First, you shouldn't be using `AsyncReaderWriterLock`. If you just want to protect the variable, then you can just use `lock`:

```
private readonly static object _mutex = new object();
private List<MyClass> my = new List<MyClass>();

public List<MyClass> My
{
  get
  {
    lock (_mutex)
    {
      return my;
    }
  }
}

...

List<MyClass> my2 = await this.Exchange.GetDataAsync();
lock (_mutex)
{
  this.my = my2;
}

```

It doesn't have to be a reader/writer lock because there's not a ton of contention around reading, and it doesn't have to be asynchronous because the code in the critical section is all synchronous.

However, I would recommend changing the type of `My` to be `IReadOnlyList<MyClass>` (or possibly even `IImmutableList<MyClass>`), so that it's clear to callers that they shouldn't be changing it.
in that case, you are not locking the list it self...
the lock need to be while you access/modify the list, not just the list variable...