mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-31 21:16:08 +02:00
Utilities: BlockingQueue.TryDequeue: Change behavior to return all items enqueued before Stop was invoked
This commit is contained in:
parent
21313ac030
commit
a9ec1878d0
1 changed files with 17 additions and 2 deletions
|
@ -17,6 +17,11 @@ namespace Utilities
|
|||
|
||||
public void Enqueue(T item)
|
||||
{
|
||||
if (m_stopping)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (m_queue)
|
||||
{
|
||||
m_queue.Enqueue(item);
|
||||
|
@ -30,10 +35,11 @@ namespace Utilities
|
|||
|
||||
public void Enqueue(List<T> items)
|
||||
{
|
||||
if (items.Count == 0)
|
||||
if (m_stopping || items.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (m_queue)
|
||||
{
|
||||
foreach (T item in items)
|
||||
|
@ -60,7 +66,7 @@ namespace Utilities
|
|||
Monitor.Wait(m_queue);
|
||||
}
|
||||
|
||||
if (m_stopping)
|
||||
if (m_stopping && m_queue.Count == 0)
|
||||
{
|
||||
item = default(T);
|
||||
return false;
|
||||
|
@ -82,6 +88,15 @@ namespace Utilities
|
|||
}
|
||||
}
|
||||
|
||||
public void Abort()
|
||||
{
|
||||
lock (m_queue)
|
||||
{
|
||||
m_queue.Clear();
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue