extensions/Wrapper/ConcurrentQueueWrapper.cs
2017-05-11 14:06:38 +02:00

37 lines
910 B
C#

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chrosey.Extensions.Wrapper
{
public class ConcurrentQueueWrapper<T>
{
private readonly ConcurrentQueue<T> queue = new ConcurrentQueue<T>();
public event EventHandler Changed;
protected virtual void OnChanged()
{
if (Changed != null) Changed(this, EventArgs.Empty);
}
public virtual void Enqueue(T item)
{
queue.Enqueue(item);
OnChanged();
}
public int Count { get { return queue.Count; } }
public virtual bool TryDequeue(out T item)
{
if (queue.TryDequeue(out item))
{
OnChanged();
return true;
}
return false;
}
}
}