diff --git a/Renci.SshClient/Renci.SshNet/Channels/Channel.cs b/Renci.SshClient/Renci.SshNet/Channels/Channel.cs index 21e3bb75..ed5248ef 100644 --- a/Renci.SshClient/Renci.SshNet/Channels/Channel.cs +++ b/Renci.SshClient/Renci.SshNet/Channels/Channel.cs @@ -531,22 +531,26 @@ namespace Renci.SshNet.Channels { this.OnDisconnected(); - // If objected is disposed or being disposed don't handle this event + // If object is disposed or being disposed don't handle this event if (this._isDisposed) return; - this._disconnectedWaitHandle.Set(); + EventWaitHandle disconnectedWaitHandle = this._disconnectedWaitHandle; + if (disconnectedWaitHandle != null) + disconnectedWaitHandle.Set(); } private void Session_ErrorOccured(object sender, ExceptionEventArgs e) { this.OnErrorOccured(e.Exception); - // If objected is disposed or being disposed don't handle this event + // If object is disposed or being disposed don't handle this event if (this._isDisposed) return; - this._errorOccuredWaitHandle.Set(); + EventWaitHandle errorOccuredWaitHandle = this._errorOccuredWaitHandle; + if (errorOccuredWaitHandle != null) + errorOccuredWaitHandle.Set(); } #region Channel message event handlers