diff --git a/Renci.SshClient/Renci.SshNet/ShellStream.cs b/Renci.SshClient/Renci.SshNet/ShellStream.cs index 0b723df3..a7c5c080 100644 --- a/Renci.SshClient/Renci.SshNet/ShellStream.cs +++ b/Renci.SshClient/Renci.SshNet/ShellStream.cs @@ -671,8 +671,16 @@ namespace Renci.SshNet { base.Dispose(disposing); + if (this._session != null) + { + this._session.Disconnected -= Session_Disconnected; + this._session.ErrorOccured -= Session_ErrorOccured; + } + if (this._channel != null) { + this._channel.DataReceived -= Channel_DataReceived; + this._channel.Closed -= Channel_Closed; this._channel.Dispose(); this._channel = null; } @@ -682,12 +690,6 @@ namespace Renci.SshNet this._dataReceived.Dispose(); this._dataReceived = null; } - - if (this._session != null) - { - this._session.Disconnected -= Session_Disconnected; - this._session.ErrorOccured -= Session_ErrorOccured; - } } ///