public void ExitWriteLock(ref ReaderWriterLockCookie cookie, int millisecondsTimeout)
        {
#if NET35_OR_GREATER || NETCOREAPP || NETSTANDARD
            if (!ReaderWriterLock.IsWriteLockHeld)
            {
                return;
            }
            ReaderWriterLock.ExitWriteLock();
            if (cookie.FromRead)
            {
                if (!ReaderWriterLock.TryEnterReadLock(millisecondsTimeout))
                {
                    throw new TimeoutException("恢复读锁超时");
                }
            }
#else
            if (!ReaderWriterLock.IsWriterLockHeld)
            {
                return;
            }
            if (cookie.FromRead)
            {
                ReaderWriterLock.DowngradeFromWriterLock(ref cookie.LockCookie);
                return;
            }
            ReaderWriterLock.ReleaseWriterLock();
#endif
        }
 public bool TryExitWriteLock(ref ReaderWriterLockCookie cookie, int millisecondsTimeout)
 {
     try {
         ExitWriteLock(ref cookie, millisecondsTimeout);
         return(true);
     } catch (ApplicationException) {
     } catch (TimeoutException) {
     }
     return(false);
 }
 public bool TryEnterWriteLock(out ReaderWriterLockCookie cookie, int millisecondsTimeout)
 {
     try {
         EnterWriteLock(out cookie, millisecondsTimeout);
         return(true);
     } catch (ApplicationException) {
     } catch (TimeoutException) {
     }
     cookie = default(ReaderWriterLockCookie);
     return(false);
 }
        public void EnterWriteLock(out ReaderWriterLockCookie cookie, int millisecondsTimeout)
        {
            cookie = new ReaderWriterLockCookie();
#if NET35_OR_GREATER || NETCOREAPP || NETSTANDARD
            if (ReaderWriterLock.IsWriteLockHeld)
            {
                return;
            }
            if (ReaderWriterLock.IsReadLockHeld)
            {
                cookie.FromRead = true;
                ReaderWriterLock.ExitReadLock();
            }
            if (!ReaderWriterLock.TryEnterWriteLock(millisecondsTimeout))
            {
                if (cookie.FromRead)
                {
                    if (!ReaderWriterLock.TryEnterReadLock(millisecondsTimeout))
                    {
                        throw new TimeoutException("恢复读锁超时");
                    }
                }
                throw new TimeoutException("获取写锁超时");
            }
#else
            if (ReaderWriterLock.IsWriterLockHeld)
            {
                return;
            }
            if (ReaderWriterLock.IsReaderLockHeld)
            {
                cookie.FromRead   = true;
                cookie.LockCookie = ReaderWriterLock.UpgradeToWriterLock(millisecondsTimeout);
                return;
            }
            ReaderWriterLock.AcquireWriterLock(millisecondsTimeout);
#endif
        }
 public bool TryExitWriteLock(ref ReaderWriterLockCookie cookie)
 {
     return(TryExitWriteLock(ref cookie, MillisecondsTimeout));
 }
 public bool TryExitWriteLock(ref ReaderWriterLockCookie cookie, TimeSpan timeout)
 {
     return(TryExitWriteLock(ref cookie, (int)timeout.TotalMilliseconds));
 }
 public void ExitWriteLock(ref ReaderWriterLockCookie cookie)
 {
     ExitWriteLock(ref cookie, MillisecondsTimeout);
 }
 public void ExitWriteLock(ref ReaderWriterLockCookie cookie, TimeSpan timeout)
 {
     ExitWriteLock(ref cookie, (int)timeout.TotalMilliseconds);
 }
 public bool TryEnterWriteLock(out ReaderWriterLockCookie cookie)
 {
     return(TryEnterWriteLock(out cookie, MillisecondsTimeout));
 }
 public bool TryEnterWriteLock(out ReaderWriterLockCookie cookie, TimeSpan timeout)
 {
     return(TryEnterWriteLock(out cookie, timeout));
 }
 public void EnterWriteLock(out ReaderWriterLockCookie cookie)
 {
     EnterWriteLock(out cookie, MillisecondsTimeout);
 }
 public void EnterWriteLock(out ReaderWriterLockCookie cookie, TimeSpan timeout)
 {
     EnterWriteLock(out cookie, (int)timeout.TotalMilliseconds);
 }