For types that have a `CancellationTokenSource` that is triggered during `Dispose()`, we should check to see if it has already been cancelled to avoid disposing twice. Implicitly, there's a race here if there are multiple threads calling `DIspose()`, but these are all handled by the DI containers we use.
This commit is contained in:
Dustin Campbell 2024-06-12 12:36:02 -07:00
Родитель 76ab7e465f
Коммит 6cfeab00ff
12 изменённых файлов: 60 добавлений и 0 удалений

Просмотреть файл

@ -83,6 +83,11 @@ internal partial class RazorDiagnosticsPublisher : IDocumentProcessedListener, I
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}

Просмотреть файл

@ -57,6 +57,11 @@ internal partial class OpenDocumentGenerator : IRazorStartupService, IDisposable
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}

Просмотреть файл

@ -63,6 +63,11 @@ internal partial class RazorProjectService : IRazorProjectService, IRazorProject
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}

Просмотреть файл

@ -50,6 +50,11 @@ internal partial class RazorFileChangeDetector : IFileChangeDetector, IDisposabl
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}

Просмотреть файл

@ -43,6 +43,11 @@ internal class WorkspaceSemanticTokensRefreshNotifier : IWorkspaceSemanticTokens
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_optionsChangeListener.Dispose();
_disposeTokenSource.Cancel();

Просмотреть файл

@ -45,6 +45,11 @@ internal abstract partial class AbstractRazorProjectInfoDriver : IRazorProjectIn
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}

Просмотреть файл

@ -168,6 +168,11 @@ internal partial class ProjectSnapshotManager
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_taskQueue.Complete();
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();

Просмотреть файл

@ -77,6 +77,11 @@ internal partial class EditorDocumentManagerListener : IRazorStartupService, IDi
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}

Просмотреть файл

@ -59,6 +59,11 @@ internal partial class BackgroundDocumentGenerator : IRazorStartupService, IDisp
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}

Просмотреть файл

@ -40,6 +40,11 @@ internal sealed class RazorActivityLog : IDisposable
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}

Просмотреть файл

@ -66,6 +66,11 @@ internal class VsSolutionUpdatesProjectSnapshotChangeTrigger : IRazorStartupServ
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();

Просмотреть файл

@ -73,6 +73,11 @@ internal partial class WorkspaceProjectStateChangeDetector : IRazorStartupServic
public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}
_projectManager.Changed -= ProjectManager_Changed;
_workspace.WorkspaceChanged -= Workspace_WorkspaceChanged;