Hi everyone,
I have implemented ReaderWriterLockSlim, Now i don't want it to wait at the lock. I want to do something else if the lock is held.
I considered using is isWriterLockHeld but it does not makes much sense to me, Since if two threads come in at the same time and enter the if statement at the same time one will still be waiting at the lock
here is my code.
ReaderWriterLockSlim rw = GetLoadingLock(parameters);
rw = GetLoadingLock(parameters);
try
{
rw.EnterWriteLock();
item = this.retrieveCacheItem(parameters.ToString(), false);
if (item != null)
{
parameters.DataCameFromCache = true;
// if the data was found in the cache, return it immediately
return item.data;
}
else
{
try
{
object loaditem = null;
itemsLoading[parameters.ToString()] = true;
loaditem = this.retrieveDataFromStore(parameters);
return loaditem;
}
finally {
itemsLoading.Remove(parameters.ToString());
}
}
}
finally
{
rw.ExitWriteLock();
}
Can anyone please guide me in the right direction with this.
Thanks