未验证 提交 ee1cf15c 编写于 作者: T Tomáš Matoušek 提交者: GitHub

Remove Dispose(disposing) from objects without finalization (#40782)

上级 d25991bb
......@@ -343,14 +343,9 @@ public Task<bool> 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);
}
}
}
}
......
......@@ -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)
......
......@@ -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
}
}
......@@ -52,17 +52,14 @@ public override Task<T> InvokeAsync<T>(string targetName, IReadOnlyList<object>
public override Task<T> InvokeAsync<T>(string targetName, IReadOnlyList<object> arguments, Func<Stream, CancellationToken, Task<T>> 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();
}
}
}
......@@ -35,14 +35,10 @@ public override Task<T> InvokeAsync<T>(string targetName, IReadOnlyList<object>
public override Task<T> InvokeAsync<T>(string targetName, IReadOnlyList<object> arguments, Func<Stream, CancellationToken, Task<T>> 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();
}
}
}
......
......@@ -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
......
......@@ -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<object> argume
public override Task<T> InvokeAsync<T>(
string targetName, IReadOnlyList<object> arguments, Func<Stream, CancellationToken, Task<T>> funcWithDirectStreamAsync, CancellationToken cancellationToken)
=> throw new NotImplementedException();
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Disposed = true;
}
}
}
}
......@@ -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)
}
/// <summary>
/// This method provides the implementation for <see cref="IDisposable.Dispose"/>. This method via the
/// <see cref="IDisposable"/> interface (i.e. <paramref name="disposing"/> is <see langword="true"/>) if the
/// constructor completes successfully. The <see cref="InitializeAsync"/> may or may not have completed
/// successfully.
/// This method provides the implementation for <see cref="IDisposable.Dispose"/>.
/// This method is called via the <see cref="IDisposable"/> interface if the constructor completes successfully.
/// The <see cref="InitializeAsync"/> may or may not have completed successfully.
/// </summary>
protected virtual void Dispose(bool disposing)
public virtual void Dispose()
{
if (disposing)
{
_messageFilter.Dispose();
}
_messageFilter.Dispose();
}
protected KeyPress Ctrl(VirtualKey virtualKey)
......
......@@ -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();
}
}
}
......@@ -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<T> InvokeAsync<T>(string targetName, IReadOnlyList<object> arguments, CancellationToken cancellationToken);
public abstract Task<T> InvokeAsync<T>(string targetName, IReadOnlyList<object> arguments, Func<Stream, CancellationToken, Task<T>> 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);
}
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册