зеркало из https://github.com/dotnet/razor.git
Don't dispose services twice
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:
Родитель
76ab7e465f
Коммит
6cfeab00ff
|
@ -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;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче