From 3025cbf4910a314d8bce738bd33ef8a537816c21 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Thu, 5 Sep 2024 11:30:08 +0200 Subject: [PATCH] Move object disposal --- Source/HiveMQtt/Client/Connection/ConnectionManager.cs | 4 ++++ Source/HiveMQtt/Client/HiveMQClientUtil.cs | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/HiveMQtt/Client/Connection/ConnectionManager.cs b/Source/HiveMQtt/Client/Connection/ConnectionManager.cs index 5343f4d1..47da4a8f 100644 --- a/Source/HiveMQtt/Client/Connection/ConnectionManager.cs +++ b/Source/HiveMQtt/Client/Connection/ConnectionManager.cs @@ -197,6 +197,10 @@ internal async Task CancelBackgroundTasksAsync() /// public void Dispose() { + // Dispose managed resources. + this.cancellationTokenSource.Cancel(); + this.cancellationTokenSource.Dispose(); + this.Dispose(); /* This object will be cleaned up by the Dispose method. diff --git a/Source/HiveMQtt/Client/HiveMQClientUtil.cs b/Source/HiveMQtt/Client/HiveMQClientUtil.cs index 6289ea0a..63bd166b 100644 --- a/Source/HiveMQtt/Client/HiveMQClientUtil.cs +++ b/Source/HiveMQtt/Client/HiveMQClientUtil.cs @@ -173,11 +173,7 @@ protected virtual void Dispose(bool disposing) Logger.Trace("HiveMQClient Dispose: Disconnecting connected client."); _ = Task.Run(async () => await this.DisconnectAsync().ConfigureAwait(false)); } - - // Dispose managed resources. - // this.cancellationTokenSource.Cancel(); - // this.cancellationTokenSource.Dispose(); - } + } // Call the appropriate methods to clean up // unmanaged resources here.