提交 e5c4f7f6 编写于 作者: S Sam Harwell

Add ForegroundNotificationService.ReleaseCancelledItems to immediately clear cancelled operations

上级 fdccb9b2
......@@ -66,6 +66,8 @@ public void RegisterNotification(Func<bool> action, int delay, IAsyncToken async
_workQueue.Enqueue(new PendingWork(current + delay, action, asyncToken, cancellationToken));
}
internal void ReleaseCancelledItems() => _workQueue.ReleaseCancelledItems();
public bool IsEmpty_TestOnly => _workQueue.IsEmpty;
private async Task ProcessAsync()
......@@ -362,6 +364,31 @@ private PendingWork Dequeue_NoLock()
return work;
}
internal void ReleaseCancelledItems()
{
var removedItems = new LinkedList<PendingWork>();
lock (_gate)
{
for (LinkedListNode<PendingWork> current = _list.First, next = current?.Next;
current != null;
current = next, next = current?.Next)
{
if (current.Value.CancellationToken.IsCancellationRequested)
{
_list.Remove(current);
removedItems.AddLast(current);
}
}
}
// Dispose of the async tokens outside the lock
foreach (var pendingWork in removedItems)
{
pendingWork.AsyncToken?.Dispose();
}
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册