未验证 提交 61978609 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #26047 from sharwell/notification-service-compat

Avoid IForegroundNotificationService interaction from tests that can't use it
......@@ -3,19 +3,18 @@
using System;
using System.Collections.Generic;
using System.Composition.Hosting;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Implementation.ForegroundNotification;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Utilities;
using Microsoft.VisualStudio.Composition;
using Roslyn.Test.Utilities;
using Xunit.Sdk;
......@@ -95,13 +94,16 @@ public override void After(MethodInfo methodUnderTest)
var listenerProvider = exportProvider?.GetExportedValues<IAsynchronousOperationListenerProvider>().SingleOrDefault();
if (listenerProvider != null)
{
// Immediately clear items from the foreground notification service for which cancellation is
// requested. This service maintains a queue separately from Tasks, and work items scheduled for
// execution after a delay are not immediately purged when cancellation is requested. This code
// instructs the service to walk the list of queued work items and immediately cancel and purge any
// which are already cancelled.
var foregroundNotificationService = exportProvider?.GetExportedValues<IForegroundNotificationService>().SingleOrDefault() as ForegroundNotificationService;
foregroundNotificationService?.ReleaseCancelledItems();
if (ForegroundThreadAffinitizedObject.CurrentForegroundThreadData.Kind != ForegroundThreadDataKind.Unknown)
{
// Immediately clear items from the foreground notification service for which cancellation is
// requested. This service maintains a queue separately from Tasks, and work items scheduled for
// execution after a delay are not immediately purged when cancellation is requested. This code
// instructs the service to walk the list of queued work items and immediately cancel and purge any
// which are already cancelled.
var foregroundNotificationService = exportProvider?.GetExportedValues<IForegroundNotificationService>().SingleOrDefault() as ForegroundNotificationService;
foregroundNotificationService?.ReleaseCancelledItems();
}
// Join remaining operations with a timeout
using (var timeoutTokenSource = new CancellationTokenSource(CleanupTimeout))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册