/// <summary>
        /// 申请写入锁
        /// </summary>
        /// <param name="rwlock">读写锁</param>
        /// <returns>Cookie对象</returns>
        public static IntelligentLockCookie WriterLock(ReaderWriterLock rwlock)
        {
            IntelligentLockCookie ilc = new IntelligentLockCookie();

            ilc.upgrade = false;
            if (rwlock.IsWriterLockHeld)
            {
                ilc.locked  = false;
                ilc.upgrade = false;
            }
            else
            {
                if (rwlock.IsReaderLockHeld)
                {
                    //注意: 在线程调用 UpgradeToWriterLock 时,不管锁计数为多少都将释放读线程锁,并且线程将转到写线程锁队列的末尾。因此,在请求升级的线程被授予写线程锁之前,其他线程可以写入资源。
                    //此操作相当危险所以暂时不使用
                    throw new AbandonedMutexException("ReaderWriterLock.UpgradeToWriterLock is dangerous method!");
                    //ilc.lc = rwlock.UpgradeToWriterLock(Timeout.Infinite);
                    //ilc.locked = true;
                    //ilc.upgrade = true;
                }
                else
                {
                    rwlock.AcquireWriterLock(Timeout.Infinite);
                    ilc.locked  = true;
                    ilc.upgrade = false;
                }
            }
            return(ilc);
        }
 /// <summary>
 /// 解除写入锁
 /// </summary>
 /// <param name="rwlock">读写锁</param>
 /// <param name="ilc">Cookie对象</param>
 public static void ReleaseWriterLock(ReaderWriterLock rwlock, IntelligentLockCookie ilc)
 {
     if (true == ilc.locked)
     {
         if (true == ilc.upgrade)
         {
             LockCookie lc = ilc.lc;
             rwlock.DowngradeFromWriterLock(ref lc);
         }
         else
         {
             rwlock.ReleaseWriterLock();
         }
     }
 }