未验证 提交 d411a232 编写于 作者: D dotnet-automerge-bot 提交者: GitHub

Merge pull request #32577 from dotnet/merges/dev16.0-preview2-to-master

Merge dev16.0-preview2 to master
......@@ -6,13 +6,14 @@ namespace Microsoft.CodeAnalysis
{
public sealed class WorkspaceRegistration
{
private Workspace _registeredWorkspace;
private readonly object _gate = new object();
internal WorkspaceRegistration()
{
}
public Workspace Workspace => _registeredWorkspace;
public Workspace Workspace { get; private set; }
public event EventHandler WorkspaceChanged;
internal void SetWorkspaceAndRaiseEvents(Workspace workspace)
......@@ -23,12 +24,30 @@ internal void SetWorkspaceAndRaiseEvents(Workspace workspace)
internal void SetWorkspace(Workspace workspace)
{
_registeredWorkspace = workspace;
Workspace = workspace;
}
internal void RaiseEvents()
{
WorkspaceChanged?.Invoke(this, EventArgs.Empty);
lock (_gate)
{
// this is a workaround for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/744145
// for preview 2.
//
// it is a workaround since we are calling event handler under a lock to make sure
// we don't raise event concurrently
//
// we have this issue to track proper fix for preview 3 or later
// https://github.com/dotnet/roslyn/issues/32551
//
// issue we are working around is the fact this event can happen concurrently
// if RegisteryText happens and then UnregisterText happens in perfect timing,
// RegisterText got slightly delayed since it is async event, and UnregisterText happens
// at the same time since it is a synchronous event, and they my happens in 2 different threads,
// cause this event to be raised concurrently.
// that can cause some listener to mess up its internal state like the issue linked above
WorkspaceChanged?.Invoke(this, EventArgs.Empty);
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册