Beispiel #1
0
 /// <summary>
 /// Inserts a type T object into the queue
 /// </summary>
 /// <param name="queueItem">T queue object</param>
 public void Enqueue(T queueItem)
 {
     using (AutoLock.LockToWrite(_lock, _timeout))
     {
         _queue.Enqueue(queueItem);
     }
 }
Beispiel #2
0
 public bool ContainsKey(K key)
 {
     using (AutoLock.LockToRead(_lock, _timeout))
     {
         return(_dictionary.ContainsKey(key));
     }
 }
Beispiel #3
0
 public bool ContainsValue(V value)
 {
     using (AutoLock.LockToRead(_lock, _timeout))
     {
         return(_dictionary.ContainsValue(value));
     }
 }
Beispiel #4
0
 public void Clear( )
 {
     using (AutoLock.LockToWrite(_lock, _timeout))
     {
         _dictionary.Clear( );
     }
 }
Beispiel #5
0
 public void Add(K key, V value)
 {
     using (AutoLock.LockToWrite(_lock, _timeout))
     {
         _dictionary.Add(key, value);
     }
 }
Beispiel #6
0
 public bool TryGetValue(K key, out V value)
 {
     using (AutoLock.LockToWrite(_lock, _timeout))
     {
         return(_dictionary.TryGetValue(key, out value));
     }
 }
Beispiel #7
0
 public void Remove(K key)
 {
     using (AutoLock.LockToWrite(_lock, _timeout))
     {
         _dictionary.Remove(key);
     }
 }
Beispiel #8
0
        /// <summary>
        /// Removes the beginning item from the queue and returns the item
        /// </summary>
        /// <returns>type T item or default T if the queue is empty</returns>
        public T Dequeue( )
        {
            using (AutoLock.LockToWrite(_lock, _timeout))
            {
                if (0 != _queue.Count)
                {
                    return(_queue.Dequeue( ));
                }
            }

            return(default(T));
        }
Beispiel #9
0
        /// <summary>
        /// Retrieves the next item in the queue without removing the item.
        /// </summary>
        /// <param name="trimWhenEmpty">true to trim the queue size when empty</param>
        /// <returns>T object or default T object when empty</returns>
        public T GetNextItem(bool trimWhenEmpty)
        {
            using (AutoLock.LockToRead(_lock, _timeout))
            {
                if (0 != _queue.Count)
                {
                    return(_queue.Peek( ));
                }
                else
                {
                    if (trimWhenEmpty)
                    {
                        // Release the queue memory (by default, once the queue grows,
                        // it won't release any allocated memory even if it's empty)
                        _queue.TrimExcess( );
                    }
                }
            }

            return(default(T));
        }
Beispiel #10
0
 public V this [K key]
 {
     get { using (AutoLock.LockToRead(_lock, _timeout)) { return(_dictionary [key]); } }
     set { using (AutoLock.LockToWrite(_lock, _timeout)) { _dictionary [key] = value; } }
 }