提交 64068ba4 编写于 作者: J Jason Malinowski

Switch some calls to ThreadHelper.ThrowIfNotOnUIThread to something else

It seems there's a flaky issue in our unit test setup where sometimes
ThrowIfNotOnUIThread will throw even if you're on the JTF main thread.
It appears the implementation relies on checking the Dispatcher object
that must sometimes not be set up right. We have a standard mechansim
anyways for asserting that we are on the UI thread that consumes our
IThreadingContext, so switching the helper we call should avoid this.
上级 a1638e3b
......@@ -56,9 +56,8 @@ internal abstract partial class AbstractLegacyProject : ForegroundThreadAffiniti
string externalErrorReportingPrefix,
HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
ICommandLineParserService commandLineParserServiceOpt)
: base(threadingContext)
: base(threadingContext, assertIsForeground: true)
{
ThreadHelper.ThrowIfNotOnUIThread();
Contract.ThrowIfNull(hierarchy);
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
......
......@@ -150,7 +150,7 @@ public VisualStudioWorkspaceImpl(ExportProvider exportProvider, IAsyncServicePro
internal void SubscribeExternalErrorDiagnosticUpdateSourceToSolutionBuildEvents()
{
ThreadHelper.ThrowIfNotOnUIThread();
_foregroundObject.AssertIsForeground();
if (_isExternalErrorDiagnosticUpdateSourceSubscribedToSolutionBuildEvents)
{
......@@ -368,7 +368,7 @@ public override EnvDTE.FileCodeModel GetFileCodeModel(DocumentId documentId)
Microsoft.CodeAnalysis.Solution newSolution,
IProgressTracker progressTracker)
{
if (!ThreadHelper.JoinableTaskContext.IsOnMainThread)
if (!_foregroundObject.IsForeground())
{
throw new InvalidOperationException(ServicesVSResources.VisualStudioWorkspace_TryApplyChanges_cannot_be_called_from_a_background_thread);
}
......@@ -453,7 +453,7 @@ internal override bool CanRenameFilesDuringCodeActions(CodeAnalysis.Project proj
internal bool IsCPSProject(CodeAnalysis.Project project)
{
ThreadHelper.ThrowIfNotOnUIThread();
_foregroundObject.AssertIsForeground();
if (this.TryGetHierarchy(project.Id, out var hierarchy))
{
......@@ -1072,7 +1072,7 @@ public void OpenDocumentCore(DocumentId documentId, bool activate = true)
throw new ArgumentNullException(nameof(documentId));
}
if (!ThreadHelper.JoinableTaskContext.IsOnMainThread)
if (!_foregroundObject.IsForeground())
{
throw new InvalidOperationException(ServicesVSResources.This_workspace_only_supports_opening_documents_on_the_UI_thread);
}
......@@ -1425,7 +1425,7 @@ public void EnsureEditableDocuments(params DocumentId[] documents)
internal override bool CanAddProjectReference(ProjectId referencingProject, ProjectId referencedProject)
{
ThreadHelper.ThrowIfNotOnUIThread();
_foregroundObject.AssertIsForeground();
if (!TryGetHierarchy(referencingProject, out var referencingHierarchy) ||
!TryGetHierarchy(referencedProject, out var referencedHierarchy))
{
......
......@@ -58,8 +58,6 @@ public bool LastDesignTimeBuildSucceeded
public CPSProject(VisualStudioProject visualStudioProject, VisualStudioWorkspaceImpl visualStudioWorkspace, IProjectCodeModelFactory projectCodeModelFactory, Guid projectGuid, string binOutputPath)
{
ThreadHelper.ThrowIfNotOnUIThread();
_visualStudioProject = visualStudioProject;
_visualStudioWorkspace = visualStudioWorkspace;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册