ReaderWriterLockSlim的许多示例都是通过这种方式编写的:
public string Read(int key)
{
cacheLock.EnterReadLock(); // is there a reason for this
try
{
return innerCache[key];
}
finally
{
cacheLock.ExitReadLock();
}
}
EnterLock是否在try块之外真的有原因吗?