ReaderWriterLockSlim.TryEnterUpgradeableReadLock(0) is blocking

230 Views Asked by At

In my .Net application, I've a place where I declare a ReaderWriterLockSlim:

    private readonly ReaderWriterLockSlim m_lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

At some other place, I refresh some value every 100ms, so basically if one time, the lock isn't accessible, this isn't a big deal, I just want to exit and wait for the next call.

So I've the following method's content:

if (m_lock.TryEnterUpgradeableReadLock(0)){
   ..
}

In the application, I'm currently having a deadlocks(which seems to have nothing to do with this current issue), so I paused my application to check the threads and I saw that I've more than 20 threads that are currently blocked on the if condition.

This is very weird, because the documentation is very clear about this:

If millisecondsTimeout is 0 (zero), this method checks the lock state and returns false immediately if the desired state is unavailable.

The question is simple. WHYYYYYYYYYYYYYYYYYYY? I tried to put breakpoints after the TryEnterUpgradeable, to just continue, but this doesn't work.

0

There are 0 best solutions below