ReaderWriterLockSlim.EnterReadLock before try block, is there a reason?

278 views Asked by At

A lot of examples for the ReaderWriterLockSlim are written this way:

public string Read(int key)
{
    cacheLock.EnterReadLock(); // is there a reason for this 
    try
    {
        return innerCache[key];
    }
    finally
    {
        cacheLock.ExitReadLock();
    }
}

Is there a real reason for the EnterLock to be outside the try block ?

0

There are 0 answers