22 lines
673 B
C#
22 lines
673 B
C#
using System.Collections.Concurrent;
|
|
|
|
namespace SHH.MjpegPlayer
|
|
{
|
|
/// <summary>
|
|
/// 辅助类:线程安全集合
|
|
/// </summary>
|
|
public class ConcurrentHashSet<T> : IEnumerable<T>
|
|
{
|
|
private readonly ConcurrentDictionary<T, byte> _dict = new ConcurrentDictionary<T, byte>();
|
|
|
|
public void Add(T item) => _dict.TryAdd(item, 0);
|
|
|
|
public void Remove(T item) => _dict.TryRemove(item, out _);
|
|
|
|
public bool IsEmpty => _dict.IsEmpty;
|
|
|
|
public IEnumerator<T> GetEnumerator() => _dict.Keys.GetEnumerator();
|
|
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
|
|
}
|
|
} |