提交 091180ae 编写于 作者: J Jason Malinowski

Throw if VisualStudioWorkspace.TryApplyChanges is called from a background thread

This is something we could support one day, but until we do let's throw
a reasonable exception instead of exploding in some bizzare way.

Fixes https://github.com/dotnet/roslyn/issues/17782
上级 1168c4cf
......@@ -126,6 +126,11 @@ private bool TryGetHostProject(ProjectId projectId, out IVisualStudioHostProject
Microsoft.CodeAnalysis.Solution newSolution,
IProgressTracker progressTracker)
{
if (_foregroundObject.IsValueCreated && !_foregroundObject.Value.IsForeground())
{
throw new InvalidOperationException(ServicesVSResources.VisualStudioWorkspace_TryApplyChanges_cannot_be_called_from_a_background_thread);
}
var projectChanges = newSolution.GetChanges(this.CurrentSolution).GetProjectChanges().ToList();
var projectsToLoad = new HashSet<Guid>();
foreach (var pc in projectChanges)
......
......@@ -2314,6 +2314,15 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to VisualStudioWorkspace.TryApplyChanges cannot be called from a background thread..
/// </summary>
internal static string VisualStudioWorkspace_TryApplyChanges_cannot_be_called_from_a_background_thread {
get {
return ResourceManager.GetString("VisualStudioWorkspace_TryApplyChanges_cannot_be_called_from_a_background_thread", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to When inserting properties, events and methods, place them:.
/// </summary>
......
......@@ -897,4 +897,7 @@ Additional information: {1}</value>
<data name="Remove_naming_rule" xml:space="preserve">
<value>Remove naming rule</value>
</data>
<data name="VisualStudioWorkspace_TryApplyChanges_cannot_be_called_from_a_background_thread" xml:space="preserve">
<value>VisualStudioWorkspace.TryApplyChanges cannot be called from a background thread.</value>
</data>
</root>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册