コード例 #1
0
 public bool ContainsKey(string key)
 {
     Lock.AcquireReaderLock(1000);
     try
     {
         return(settings.ContainsKey(key));
     }
     finally
     {
         Lock.ReleaseReaderLock();
     }
 }
コード例 #2
0
        /// <summary>
        /// 获取指定的键相关联值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool TryGetValue(TKey key, out TValue value)
        {
            rwLock.AcquireReaderLock(lockTimeOut);
            bool result;

            try
            {
                result = dictionary.TryGetValue(key, out value);
            }
            finally
            {
                rwLock.ReleaseReaderLock();
            }
            return(result);
        }
コード例 #3
0
ファイル: Vertex.cs プロジェクト: schwarzertod/NETGen
        /// <summary>
        /// Returns a reference to the (directed or indirected) edge that connects to a  specific successor vertex. This can either be
        /// a directed edge starting from this vertex and arriving in the successor or an undirected edge connecting both vertices. This operation is thread-safe.
        /// </summary>
        /// <param name="successor">The successor to which this vertex connects</param>
        /// <returns>The edge between this vertex and the successor in question or null if no such edge exists</returns>
        public Edge GetEdgeToSuccessor(Vertex successor)
        {
            _rwl.AcquireReaderLock(-1);

            Edge e = null;

            if (_successorToEdgeMap.ContainsKey(successor.ID))
            {
                e = _successorToEdgeMap[successor.ID];
            }

            _rwl.ReleaseReaderLock();

            return(e);
        }
コード例 #4
0
ファイル: Lock.cs プロジェクト: H1GHGuY/ServerCheckerV4
        private void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            System.Diagnostics.Debug.Assert(disposing);

            if (cookie.HasValue)
            {
                DowngradeToReaderLock();
            }

            if (type == LockType.ForReading)
            {
                rwlock.ReleaseReaderLock();
            }
            else if (type == LockType.ForWriting)
            {
                rwlock.ReleaseWriterLock();
            }

            disposed = true;
        }
コード例 #5
0
 /// <summary>
 /// Notifies all registered event handlers of the occurance of an event!
 /// </summary>
 /// <param name="e">The event that occured</param>
 /// <param name="sender">The sender of this event</param>
 /// <param name="eArgs">The event arguments</param>
 /// <remarks>Overwrite the EventArgs class to set own arguments</remarks>
 public void Notify(RoadEvent e, object sender, EventArgs eArgs)
 {
     try
     {
         m_lock.AcquireReaderLock(TIMEOUT);
         WeakMulticastDelegate eventDelegate;
         try
         {
             eventDelegate = (WeakMulticastDelegate)m_events[e];
         }
         finally
         {
             m_lock.ReleaseReaderLock();
         }
         if (eventDelegate == null)
         {
             return;
         }
         eventDelegate.InvokeSafe(new object[] { e, sender, eArgs });
     }
     catch (ApplicationException ex)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Failed to notify event handler!", ex);
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// 查找符合条件的对象,并将它们存入一个list中
        /// </summary>
        /// <param name="adapter">查找条件</param>
        /// <returns>如果返回的list的长度为0,表示没有找到符合条件的对象</returns>
        public List <T> Search(int adapter, Hashtable paraset)
        {
            List <T> result = null;

            try
            {
                obj_rwl.AcquireReaderLock(System.Threading.Timeout.Infinite);
                //在对象集合中寻找
                int getall;//根据管理策略的不同而选择不同的值,如果该策略缓存了所有的数据,则getall为1,表示不需要再到数据库中查询了。
                result = this.obj_dependency.Search(ref this.obj_containers, adapter, paraset, out getall);
                obj_rwl.ReleaseReaderLock();

                if (0 == getall)
                {
                    obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                    result.Clear();
                    result = SearchDB(adapter, paraset);
                    if (result.Count > 0)
                    {
                        foreach (T t in result)
                        {
                            this.obj_dependency.Insert(t.GetMyGuid(), new CCacheItem_WuQi <K, T>(t.GetMyGuid(), t), ref this.obj_containers);
                        }
                    }
                    obj_rwl.ReleaseWriterLock();
                }
            }
            catch (System.Exception e)
            {
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                if (obj_rwl.IsReaderLockHeld)
                {
                    obj_rwl.ReleaseReaderLock();
                }
                if (obj_rwl.IsWriterLockHeld)
                {
                    obj_rwl.ReleaseWriterLock();
                }
            }
            return(result);
        }
コード例 #7
0
 public TResult Read <TResult>(Func <T, TResult> readMethod)
 {
     readerWriterLock.AcquireReaderLock(int.MaxValue);
     try
     {
         return(readMethod(data));
     }
     finally { readerWriterLock.ReleaseReaderLock(); }
 }
コード例 #8
0
        public bool IsCodeUsed(long timestamp, String code, object user)
        {
            try
            {
                rwlock.AcquireReaderLock(lockingTimeout);

                return(codes.Contains(new UsedCode(timestamp, code, user)));
            }
            finally
            {
                rwlock.ReleaseReaderLock();
            }
        }
コード例 #9
0
 public ToJSON()
 {
     try
     {
         _rw_lock.AcquireReaderLock(5000); // or whatever you deem an acceptable timeout
         string s = "";                    // Serialize here using Newtonsoft
         return(s);
     }
     finally
     {
         _rw_lock.ReleaseReaderLock();
     }
 }
コード例 #10
0
ファイル: Lock.Read.cs プロジェクト: perryiv/cadkit
 /// <summary>
 /// Dispose this instance.
 /// </summary>
 void System.IDisposable.Dispose()
 {
     if (null != _lock)
     {
         // If this thread hold a write-lock when this instance was created
         // (see constructor) then no read-lock was acquired.
         // Note: this design assumes the scope of the write-lock held bigger
         // than this instance.
         if (true == _lock.IsReaderLockHeld)
         {
             _lock.ReleaseReaderLock();
             this._decrementCount();
             //this._printCount();
         }
     }
 }
コード例 #11
0
            public override void CopyTo(BillType[] array)
            {
                rwLock.AcquireReaderLock(timeout);

                try
                {
                    collection.CopyTo(array);
                }
                finally
                {
                    rwLock.ReleaseReaderLock();
                }
            }
コード例 #12
0
            public override void CopyTo(Property[] array)
            {
                _rwLock.AcquireReaderLock(Timeout);

                try
                {
                    _collection.CopyTo(array);
                }
                finally
                {
                    _rwLock.ReleaseReaderLock();
                }
            }
コード例 #13
0
            public override void CopyTo(StatementPhoneNumber[] array)
            {
                rwLock.AcquireReaderLock(timeout);

                try
                {
                    collection.CopyTo(array);
                }
                finally
                {
                    rwLock.ReleaseReaderLock();
                }
            }
            public override void CopyTo(eServiceCategory[] array)
            {
                rwLock.AcquireReaderLock(timeout);

                try
                {
                    collection.CopyTo(array);
                }
                finally
                {
                    rwLock.ReleaseReaderLock();
                }
            }
コード例 #15
0
            public override void CopyTo(PreviousPayment[] array)
            {
                rwLock.AcquireReaderLock(timeout);

                try
                {
                    collection.CopyTo(array);
                }
                finally
                {
                    rwLock.ReleaseReaderLock();
                }
            }
コード例 #16
0
 /// <summary>
 /// Recupera a classe dinâmica associada com as propriedades informada.
 /// </summary>
 /// <param name="properties"></param>
 /// <returns></returns>
 public Type GetDynamicClass(IEnumerable <DynamicProperty> properties)
 {
     rwLock.AcquireReaderLock(System.Threading.Timeout.Infinite);
     try
     {
         Signature signature = new Signature(properties);
         Type      type;
         if (!classes.TryGetValue(signature, out type))
         {
             type = CreateDynamicClass(signature.Properties);
             classes.Add(signature, type);
         }
         return(type);
     }
     finally
     {
         rwLock.ReleaseReaderLock();
     }
 }
コード例 #17
0
ファイル: MFIOLock.cs プロジェクト: momo-doct/SoundCode
 /// <summary>
 /// 释放读者锁
 /// </summary>
 public void ReleaseReaderLock()
 {
     m_lock.ReleaseReaderLock();
 }