diff --git a/src/EditorFeatures/Test/Diagnostics/DiagnosticDataSerializerTests.cs b/src/EditorFeatures/Test/Diagnostics/DiagnosticDataSerializerTests.cs index c2fa255416c67e9caed2f253a63fad690548d098..a11b11d1506053ab3044546f448e24ed5371b0fd 100644 --- a/src/EditorFeatures/Test/Diagnostics/DiagnosticDataSerializerTests.cs +++ b/src/EditorFeatures/Test/Diagnostics/DiagnosticDataSerializerTests.cs @@ -343,14 +343,9 @@ public Task WriteStreamAsync(Document document, string name, Stream stream return SpecializedTasks.True; } - protected virtual void Dispose(bool disposing) + public virtual void Dispose() { } - - public void Dispose() - { - Dispose(true); - } } } } diff --git a/src/EditorFeatures/TestUtilities/Remote/InProcRemostHostClient.cs b/src/EditorFeatures/TestUtilities/Remote/InProcRemostHostClient.cs index 7c47d7ec5460dd6f9912c6618f78bdf77ad9b03d..8d2e0844cd4451ed02a5ffa87d47bc3e3d5552ef 100644 --- a/src/EditorFeatures/TestUtilities/Remote/InProcRemostHostClient.cs +++ b/src/EditorFeatures/TestUtilities/Remote/InProcRemostHostClient.cs @@ -103,14 +103,14 @@ protected override void OnStarted() { } - protected override void Dispose(bool disposing) + public override void Dispose() { // we are asked to disconnect. unsubscribe and dispose to disconnect _endPoint.Disconnected -= OnDisconnected; _endPoint.Dispose(); _remotableDataRpc.Dispose(); - base.Dispose(disposing); + base.Dispose(); } private void OnDisconnected(JsonRpcDisconnectedEventArgs e) diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs index 1babea1833d4bb6be5d90f233a83c2eaa9a74379..e3d2e4c9616a173de60eb1fe3468caa2f7f2efaf 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs @@ -236,26 +236,18 @@ private bool TryGetBuffer(uint docCookie, out ITextBuffer textBuffer) return false; } - #region IDisposable Support - private void Dispose(bool disposing) + public void Dispose() { - if (!_isDisposed) + if (_isDisposed) { - if (disposing) - { - var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable; - runningDocumentTableForEvents.UnadviseRunningDocTableEvents(_runningDocumentTableEventsCookie); - _runningDocumentTableEventsCookie = 0; - } - - _isDisposed = true; + return; } - } - public void Dispose() - { - Dispose(true); + var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable; + runningDocumentTableForEvents.UnadviseRunningDocTableEvents(_runningDocumentTableEventsCookie); + _runningDocumentTableEventsCookie = 0; + + _isDisposed = true; } - #endregion } } diff --git a/src/VisualStudio/Core/Def/Implementation/Remote/JsonRpcConnection.cs b/src/VisualStudio/Core/Def/Implementation/Remote/JsonRpcConnection.cs index 558dc6444c3afcedcf508c04b03d38e9cbba8473..bdfa23f986be4009830e505f8e49492458689cb0 100644 --- a/src/VisualStudio/Core/Def/Implementation/Remote/JsonRpcConnection.cs +++ b/src/VisualStudio/Core/Def/Implementation/Remote/JsonRpcConnection.cs @@ -52,17 +52,14 @@ public override Task InvokeAsync(string targetName, IReadOnlyList public override Task InvokeAsync(string targetName, IReadOnlyList arguments, Func> directStreamReader, CancellationToken cancellationToken) => _serviceEndPoint.InvokeAsync(targetName, arguments, directStreamReader, cancellationToken); - protected override void Dispose(bool disposing) + protected override void DisposeImpl() { - if (disposing) - { - // dispose service and snapshot channels - _serviceEndPoint.UnexpectedExceptionThrown -= UnexpectedExceptionThrown; - _serviceEndPoint.Dispose(); - _remoteDataRpc.Dispose(); - } + // dispose service and snapshot channels + _serviceEndPoint.UnexpectedExceptionThrown -= UnexpectedExceptionThrown; + _serviceEndPoint.Dispose(); + _remoteDataRpc.Dispose(); - base.Dispose(disposing); + base.DisposeImpl(); } } } diff --git a/src/VisualStudio/Core/Def/Implementation/Remote/ServiceHubRemoteHostClient.PooledConnection.cs b/src/VisualStudio/Core/Def/Implementation/Remote/ServiceHubRemoteHostClient.PooledConnection.cs index 1b5e10ece69e89bd780f9f078f20e1a037191006..13232d8889d253158937f48f8429bf28b35c6fe1 100644 --- a/src/VisualStudio/Core/Def/Implementation/Remote/ServiceHubRemoteHostClient.PooledConnection.cs +++ b/src/VisualStudio/Core/Def/Implementation/Remote/ServiceHubRemoteHostClient.PooledConnection.cs @@ -35,14 +35,10 @@ public override Task InvokeAsync(string targetName, IReadOnlyList public override Task InvokeAsync(string targetName, IReadOnlyList arguments, Func> directStreamReader, CancellationToken cancellationToken) => _connection.InvokeAsync(targetName, arguments, directStreamReader, cancellationToken); - protected override void Dispose(bool disposing) + protected override void DisposeImpl() { - if (disposing) - { - _connectionManager.Free(_serviceName, _connection); - } - - base.Dispose(disposing); + _connectionManager.Free(_serviceName, _connection); + base.DisposeImpl(); } } } diff --git a/src/VisualStudio/Core/Def/Implementation/Remote/ServiceHubRemoteHostClient.cs b/src/VisualStudio/Core/Def/Implementation/Remote/ServiceHubRemoteHostClient.cs index 3815beb2036ef82350f272c29d4545d4acf9730c..e17f4635435d2d4f7d3f625f9bbc2a4ea7a63945 100644 --- a/src/VisualStudio/Core/Def/Implementation/Remote/ServiceHubRemoteHostClient.cs +++ b/src/VisualStudio/Core/Def/Implementation/Remote/ServiceHubRemoteHostClient.cs @@ -169,7 +169,7 @@ protected override void OnStarted() RegisterGlobalOperationNotifications(); } - protected override void Dispose(bool disposing) + public override void Dispose() { // cancel all pending async work _shutdownCancellationTokenSource.Cancel(); @@ -187,7 +187,7 @@ protected override void Dispose(bool disposing) _connectionManager.Dispose(); - base.Dispose(disposing); + base.Dispose(); } public HostGroup HostGroup diff --git a/src/VisualStudio/Core/Test.Next/Services/VisualStudioDiagnosticAnalyzerExecutorTests.cs b/src/VisualStudio/Core/Test.Next/Services/VisualStudioDiagnosticAnalyzerExecutorTests.cs index 324d88cf1e057f7bcbcdf4fbc4ab27b71886ae35..84264bd3ab442f406e890ab53bb10f1b06adfe25 100644 --- a/src/VisualStudio/Core/Test.Next/Services/VisualStudioDiagnosticAnalyzerExecutorTests.cs +++ b/src/VisualStudio/Core/Test.Next/Services/VisualStudioDiagnosticAnalyzerExecutorTests.cs @@ -333,12 +333,10 @@ public MyUpdateSource(Workspace workspace) public override Workspace Workspace => _workspace; } - private class InvokeThrowsCancellationConnection : RemoteHostClient.Connection + private sealed class InvokeThrowsCancellationConnection : RemoteHostClient.Connection { private readonly CancellationTokenSource _source; - public bool Disposed = false; - public InvokeThrowsCancellationConnection(CancellationTokenSource source) { _source = source; @@ -360,13 +358,6 @@ public override Task InvokeAsync(string targetName, IReadOnlyList argume public override Task InvokeAsync( string targetName, IReadOnlyList arguments, Func> funcWithDirectStreamAsync, CancellationToken cancellationToken) => throw new NotImplementedException(); - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - Disposed = true; - } } } } diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractIntegrationTest.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractIntegrationTest.cs index f89238647c044d74b9a625894e99d62aa404bfa3..a95b227cf7f6eeb70263551a54eb1bdfb5516017 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractIntegrationTest.cs +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractIntegrationTest.cs @@ -77,12 +77,6 @@ public virtual Task DisposeAsync() return Task.CompletedTask; } - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - protected virtual MessageFilter RegisterMessageFilter() => new MessageFilter(); @@ -93,17 +87,13 @@ protected void Wait(double seconds) } /// - /// This method provides the implementation for . This method via the - /// interface (i.e. is ) if the - /// constructor completes successfully. The may or may not have completed - /// successfully. + /// This method provides the implementation for . + /// This method is called via the interface if the constructor completes successfully. + /// The may or may not have completed successfully. /// - protected virtual void Dispose(bool disposing) + public virtual void Dispose() { - if (disposing) - { - _messageFilter.Dispose(); - } + _messageFilter.Dispose(); } protected KeyPress Ctrl(VirtualKey virtualKey) diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/Harness/MessageFilter.cs b/src/VisualStudio/IntegrationTest/TestUtilities/Harness/MessageFilter.cs index 437362df6cecca3ab413c9ee6f0c23d7f3b9814d..63bdd62ea35416429f6feca4232f5f657f4c0595 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/Harness/MessageFilter.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/Harness/MessageFilter.cs @@ -8,9 +8,9 @@ namespace Microsoft.VisualStudio.IntegrationTest.Utilities.Harness { - public class MessageFilter : IMessageFilter, IDisposable + public sealed class MessageFilter : IMessageFilter, IDisposable { - protected const uint CancelCall = ~0U; + private const uint CancelCall = ~0U; private readonly MessageFilterSafeHandle _messageFilterRegistration; private readonly TimeSpan _timeout; @@ -28,12 +28,12 @@ public MessageFilter(TimeSpan timeout, TimeSpan retryDelay) _messageFilterRegistration = MessageFilterSafeHandle.Register(this); } - public virtual uint HandleInComingCall(uint dwCallType, IntPtr htaskCaller, uint dwTickCount, INTERFACEINFO[] lpInterfaceInfo) + public uint HandleInComingCall(uint dwCallType, IntPtr htaskCaller, uint dwTickCount, INTERFACEINFO[] lpInterfaceInfo) { return (uint)SERVERCALL.SERVERCALL_ISHANDLED; } - public virtual uint RetryRejectedCall(IntPtr htaskCallee, uint dwTickCount, uint dwRejectType) + public uint RetryRejectedCall(IntPtr htaskCallee, uint dwTickCount, uint dwRejectType) { if ((SERVERCALL)dwRejectType != SERVERCALL.SERVERCALL_RETRYLATER && (SERVERCALL)dwRejectType != SERVERCALL.SERVERCALL_REJECTED) @@ -49,23 +49,14 @@ public virtual uint RetryRejectedCall(IntPtr htaskCallee, uint dwTickCount, uint return (uint)_retryDelay.TotalMilliseconds; } - public virtual uint MessagePending(IntPtr htaskCallee, uint dwTickCount, uint dwPendingType) + public uint MessagePending(IntPtr htaskCallee, uint dwTickCount, uint dwPendingType) { return (uint)PENDINGMSG.PENDINGMSG_WAITDEFPROCESS; } - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - _messageFilterRegistration.Dispose(); - } - } - public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); + _messageFilterRegistration.Dispose(); } } } diff --git a/src/Workspaces/Core/Portable/Remote/RemoteHostClient.cs b/src/Workspaces/Core/Portable/Remote/RemoteHostClient.cs index 3f893e221559f10a1fd3885ebf073284f666fd1c..1c30d6a56f614d32a4273d3dd68f527822141351 100644 --- a/src/Workspaces/Core/Portable/Remote/RemoteHostClient.cs +++ b/src/Workspaces/Core/Portable/Remote/RemoteHostClient.cs @@ -53,12 +53,7 @@ protected void Started() OnStatusChanged(started: true); } - public void Dispose() - { - Dispose(disposing: true); - } - - protected virtual void Dispose(bool disposing) + public virtual void Dispose() { OnStatusChanged(started: false); } @@ -220,7 +215,7 @@ protected Connection() public abstract Task InvokeAsync(string targetName, IReadOnlyList arguments, CancellationToken cancellationToken); public abstract Task InvokeAsync(string targetName, IReadOnlyList arguments, Func> funcWithDirectStreamAsync, CancellationToken cancellationToken); - protected virtual void Dispose(bool disposing) + protected virtual void DisposeImpl() { // do nothing } @@ -234,7 +229,7 @@ public void Dispose() _disposed = true; - Dispose(disposing: true); + DisposeImpl(); GC.SuppressFinalize(this); } diff --git a/src/Workspaces/Core/Portable/TemporaryStorage/TemporaryStorageServiceFactory.MemoryMappedInfo.cs b/src/Workspaces/Core/Portable/TemporaryStorage/TemporaryStorageServiceFactory.MemoryMappedInfo.cs index cf62cc4895b4abc5a40704ee81ab4accf12ec19c..623e3d6fe5621bd42ce6d95e1d7ebdde7b3be322 100644 --- a/src/Workspaces/Core/Portable/TemporaryStorage/TemporaryStorageServiceFactory.MemoryMappedInfo.cs +++ b/src/Workspaces/Core/Portable/TemporaryStorage/TemporaryStorageServiceFactory.MemoryMappedInfo.cs @@ -169,18 +169,9 @@ public Stream CreateWritableStream() public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (disposing) - { - // See remarks on field for relation between _memoryMappedFile and the views/streams. There is no - // need to write _weakReadAccessor here since lifetime of the target is not owned by this instance. - _memoryMappedFile.Dispose(); - } + // See remarks on field for relation between _memoryMappedFile and the views/streams. There is no + // need to write _weakReadAccessor here since lifetime of the target is not owned by this instance. + _memoryMappedFile.Dispose(); } private unsafe sealed class SharedReadableStream : Stream, ISupportDirectMemoryAccess