Empty the queue at least

This commit is contained in:
Matt Nadareski
2021-04-01 19:08:39 -07:00
parent 58028b4f18
commit d2c504898a
2 changed files with 6 additions and 5 deletions

View File

@@ -44,6 +44,7 @@ namespace MPF.Data
/// <param name="item"></param>
public void Enqueue(T item)
{
// Only accept new data when not cancelled
if (!this.TokenSource.IsCancellationRequested)
this.InternalQueue.Enqueue(item);
}
@@ -55,13 +56,14 @@ namespace MPF.Data
{
while (true)
{
// If cancellation was requested, just do it
if (this.TokenSource.IsCancellationRequested)
break;
// Nothing in the queue means we get to idle
if (this.InternalQueue.Count == 0)
{
if (this.TokenSource.IsCancellationRequested)
break;
continue;
}
// Get the next item from the queue
if (!this.InternalQueue.TryDequeue(out T nextItem))