diff --git a/src/EditorFeatures/Core/Implementation/ForegroundNotification/ForegroundNotificationService.cs b/src/EditorFeatures/Core/Implementation/ForegroundNotification/ForegroundNotificationService.cs index 3cf7f628886e4550a017a9d2d7193800c5731d97..1aed8a195646861bc4b8196879e005f41ee6d278 100644 --- a/src/EditorFeatures/Core/Implementation/ForegroundNotification/ForegroundNotificationService.cs +++ b/src/EditorFeatures/Core/Implementation/ForegroundNotification/ForegroundNotificationService.cs @@ -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 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));