The following code is from MSDN:

private ReaderWriterLockSlim cacheLock = new ReaderWriterLockSlim();
private Dictionary<int, string> innerCache = new Dictionary<int, string>();

public void Add(int key, string value)
{
    cacheLock.EnterWriteLock();
    try
    {
        innerCache.Add(key, value);
    }
    finally
    {
        cacheLock.ExitWriteLock();
    }
}

I've seen code like this in other places.The EnterWriteLock() is always outside the try block. Does anyone know why it's not inside the try block?

Edit
Report