コード例 #1
0
 /// <summary>
 /// Prevents read operations from deadlocking by throwing a TimeoutException if the ReadWaitEvent is not available within <see cref="ReadWriteTimeout"/> milliseconds
 /// </summary>
 private void ReadWait()
 {
     if (!ReadWaitEvent.WaitOne(ReadWriteTimeout))
     {
         throw new TimeoutException("The read operation timed out waiting for the read lock WaitEvent. Check your usage of AcquireWriteLock/ReleaseWriteLock and AcquireReadLock/ReleaseReadLock.");
     }
 }
コード例 #2
0
 /// <summary>
 /// Prevents read operations from deadlocking by throwing a <see cref="TimeoutException"/> if <see cref="ReadWaitEvent"/> is not available
 /// within <see cref="ReadWriteTimeout"/>.
 /// </summary>
 private void ReadWait()
 {
     if (!ReadWaitEvent.WaitOne(ReadWriteTimeout))
     {
         throw new TimeoutException(RS.ReadOperationTimedOut);
     }
 }
コード例 #3
0
 /// <summary>
 /// Blocks the current thread until it is able to acquire a read lock. If successful all subsequent writes will be blocked until after a call to <see cref="ReleaseReadLock"/>.
 /// </summary>
 /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.</param>
 /// <returns>true if the read lock was able to be acquired, otherwise false.</returns>
 /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a negative number other than -1, which represents an infinite time-out.</exception>
 /// <remarks>If <paramref name="millisecondsTimeout"/> is <see cref="System.Threading.Timeout.Infinite" /> (-1), then attempting to acquire a read lock after acquiring a write lock on the same thread will result in a deadlock.</remarks>
 public bool AcquireReadLock(int millisecondsTimeout = System.Threading.Timeout.Infinite)
 {
     if (!ReadWaitEvent.WaitOne(millisecondsTimeout))
     {
         return(false);
     }
     WriteWaitEvent.Reset();
     return(true);
 }