Difference between EnterWriteLock and TryEnterWriteLock(Timeout.Infinite)

299 Views Asked by At

i'm a bit confused on the differences between EnterWriteLock() and TryEnterWriteLock() with Timeout.Infinite as parameter of ReaderWriterLockSlim. What is the point of giving an infinite timeout for entering the lock instead of using directly EnterWriteLock? What i have understood those two methods are exectly the same? What I am missing?

1

There are 1 best solutions below

0
canton7 On BEST ANSWER

They're identical:

public void EnterWriteLock()
{
    TryEnterWriteLock(-1);
}

It's a bit easier to read the intent of lock.EnterWriteLock(), compared to lock.TryEnterWriteLock(-1) / lock.TryEnterWriteLock(Timeout.Infinite).