提交 41dda865 编写于 作者: J Jason Malinowski

Add a Workspace async operation around us queueing stuff to the UI thread

Since we're checking the RDT asynchronously, we need a way for
integration tests to confirm that.
上级 e33dbac4
......@@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
......@@ -30,6 +31,7 @@ public sealed class OpenFileTracker
private readonly VisualStudioWorkspaceImpl _workspace;
private readonly IVsRunningDocumentTable4 _runningDocumentTable;
private readonly IVsEditorAdaptersFactoryService _editorAdaptersFactoryService;
private readonly IAsynchronousOperationListener _asyncOperationListener;
#region Fields read/written to from multiple threads to track files that need to be checked
......@@ -70,6 +72,7 @@ private OpenFileTracker(VisualStudioWorkspaceImpl workspace, IVsRunningDocumentT
_foregroundAffinitization = new ForegroundThreadAffinitizedObject(workspace._threadingContext, assertIsForeground: true);
_runningDocumentTable = runningDocumentTable;
_editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
_asyncOperationListener = componentModel.GetService<IAsynchronousOperationListenerProvider>().GetListener(FeatureAttribute.Workspace);
}
public async static Task<OpenFileTracker> CreateAsync(VisualStudioWorkspaceImpl workspace, IAsyncServiceProvider asyncServiceProvider)
......@@ -374,12 +377,14 @@ public void CheckForFilesBeingOpen(ImmutableArray<string> newFileNames)
if (shouldStartTask)
{
var asyncToken = _asyncOperationListener.BeginAsyncOperation(nameof(CheckForFilesBeingOpen));
Task.Run(async () =>
{
await _foregroundAffinitization.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();
CheckForFilesBeingOpenOnUIThread();
});
}).CompletesAsyncOperation(asyncToken);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册