提交 014ac5c4 编写于 作者: M Manish Vasani

Use lock for _lasActiveDocument field.

上级 3cb849ea
......@@ -21,6 +21,7 @@ internal partial class SolutionCrawlerRegistrationService
private partial class WorkCoordinator
{
private readonly Registration _registration;
private readonly object _gate;
private readonly LogAggregator _logAggregator;
private readonly IAsynchronousOperationListener _listener;
......@@ -46,6 +47,7 @@ private partial class WorkCoordinator
_logAggregator = new LogAggregator();
_registration = registration;
_gate = new object();
_listener = listener;
_optionService = _registration.GetService<IOptionService>();
......@@ -213,11 +215,15 @@ private void OnActiveDocumentChanged(object sender, DocumentId activeDocumentId)
var activeDocument = _registration.Workspace.CurrentSolution.GetDocument(activeDocumentId);
if (activeDocument != null)
{
var lastActiveDocument = Interlocked.Exchange(ref _lastActiveDocument, activeDocument);
if (lastActiveDocument != null)
lock (_gate)
{
asyncToken = _listener.BeginAsyncOperation("OnDocumentClosed");
EnqueueEvent(lastActiveDocument.Project.Solution, lastActiveDocument.Id, InvocationReasons.DocumentClosed, asyncToken);
if (_lastActiveDocument != null)
{
asyncToken = _listener.BeginAsyncOperation("OnDocumentClosed");
EnqueueEvent(_lastActiveDocument.Project.Solution, _lastActiveDocument.Id, InvocationReasons.DocumentClosed, asyncToken);
}
_lastActiveDocument = activeDocument;
}
asyncToken = _listener.BeginAsyncOperation("OnDocumentChanged");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册