#if NET20 || NET30 || NET35 || !NET_4_6 using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; //using System.Security.Permissions; using LinqInternal.Collections; using LinqInternal.Collections.ThreadSafe; namespace System.Collections.Concurrent { [SerializableAttribute] [ComVisible(false)] [DebuggerDisplay("Count = {Count}")] //[HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)] public class ConcurrentQueue : IProducerConsumerCollection, IReadOnlyCollection { private readonly SafeQueue _wrapped; public ConcurrentQueue() { _wrapped = new SafeQueue(); } public ConcurrentQueue(IEnumerable collection) { _wrapped = new SafeQueue(collection); } public int Count { get { return _wrapped.Count; } } public bool IsEmpty { get { return _wrapped.Count == 0; } } bool ICollection.IsSynchronized { get { return false; } } object ICollection.SyncRoot { get { throw new NotSupportedException(); } } public void CopyTo(T[] array, int index) { Extensions.CanCopyTo(Count, array, index); Extensions.CopyTo(this, array, index); } public void Enqueue(T item) { _wrapped.Add(item); } public IEnumerator GetEnumerator() { return _wrapped.GetEnumerator(); } void ICollection.CopyTo(Array array, int index) { Extensions.CanCopyTo(Count, array, index); this.DeprecatedCopyTo(array, index); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } bool IProducerConsumerCollection.TryAdd(T item) { _wrapped.Add(item); return true; } bool IProducerConsumerCollection.TryTake(out T item) { return _wrapped.TryTake(out item); } public T[] ToArray() { return _wrapped.ToArray(); } public bool TryDequeue(out T result) { return _wrapped.TryTake(out result); } public bool TryPeek(out T result) { return _wrapped.TryPeek(out result); } } } #endif