Change Util.cs to Helper.cs, and move ThreadSafeList to HISP.Util namespace.

This commit is contained in:
Li 2022-09-05 14:56:28 +12:00
parent c36eda289a
commit 825d3b4740
37 changed files with 197 additions and 169 deletions

View file

@ -0,0 +1,67 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading;
namespace HISP.Util
{
public class ThreadSafeList<T> : List<T>
{
private Mutex listLock = new Mutex();
new public void AddRange(IEnumerable<T> collection)
{
listLock.WaitOne();
base.AddRange(collection);
listLock.ReleaseMutex();
}
new public void Add(T value)
{
listLock.WaitOne();
base.Add(value);
listLock.ReleaseMutex();
}
new public void Clear()
{
listLock.WaitOne();
base.Clear();
listLock.ReleaseMutex();
}
new public bool Contains(T value)
{
listLock.WaitOne();
bool test = base.Contains(value);
listLock.ReleaseMutex();
return test;
}
new public IEnumerator GetEnumerator()
{
listLock.WaitOne();
IEnumerator res = base.ToArray().GetEnumerator();
listLock.ReleaseMutex();
return res;
}
new public void Insert(int index, T value)
{
listLock.WaitOne();
base.Insert(index, value);
listLock.ReleaseMutex();
}
new public void Remove(T value)
{
listLock.WaitOne();
base.Remove(value);
listLock.ReleaseMutex();
}
new public void RemoveAt(int index)
{
listLock.WaitOne();
base.RemoveAt(index);
listLock.ReleaseMutex();
}
}
}