pull/1/head
Ogoun 5 years ago
commit 919d85cfc8

@ -10,7 +10,7 @@ namespace ZeroLevel.Utils
{ {
private BlockingCollection<T> _queue = new BlockingCollection<T>(); private BlockingCollection<T> _queue = new BlockingCollection<T>();
private List<Thread> _threads = new List<Thread>(); private List<Thread> _threads = new List<Thread>();
private bool _is_disposed = false; private volatile bool _is_disposed = false;
private int _tasks_in_progress = 0; private int _tasks_in_progress = 0;
public int Count => _queue.Count + _tasks_in_progress; public int Count => _queue.Count + _tasks_in_progress;
@ -30,7 +30,7 @@ namespace ZeroLevel.Utils
Interlocked.Increment(ref _tasks_in_progress); Interlocked.Increment(ref _tasks_in_progress);
try try
{ {
handler(item); handler?.Invoke(item);
} }
finally finally
{ {
@ -72,18 +72,12 @@ namespace ZeroLevel.Utils
public void Dispose() public void Dispose()
{ {
_is_disposed = true; _is_disposed = true;
_queue.CompleteAdding(); try
Thread.Yield();
_queue.Dispose();
foreach (var thread in _threads)
{ {
try _queue.CompleteAdding();
{ _queue.Dispose();
thread.Join();
thread.Abort();
}
catch { }
} }
catch { }
} }
} }
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.