提交 8ede7e47 编写于 作者: S Sam Harwell

Avoid scheduling work that's already cancelled

While it doesn't make sense to still be requesting foreground actions after
cancellation is requested, tracking down all callers of
IForegroundNotificationService to ensure the proper checks are in place can be
tedious. This change treats IForegroundNotificationService as the gatekeeper
for scheduling asynchronous operations, and proactively cancels operations if
requested before adding them to the work queue.
上级 a4eb4099
......@@ -52,6 +52,12 @@ public void RegisterNotification(Action action, int delay, IAsyncToken asyncToke
{
Contract.Requires(delay >= 0);
if (cancellationToken.IsCancellationRequested)
{
asyncToken?.Dispose();
return;
}
var current = Environment.TickCount;
_workQueue.Enqueue(new PendingWork(current + delay, action, asyncToken, cancellationToken));
......@@ -61,6 +67,12 @@ public void RegisterNotification(Func<bool> action, int delay, IAsyncToken async
{
Contract.Requires(delay >= 0);
if (cancellationToken.IsCancellationRequested)
{
asyncToken?.Dispose();
return;
}
var current = Environment.TickCount;
_workQueue.Enqueue(new PendingWork(current + delay, action, asyncToken, cancellationToken));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册