diff --git a/InTheHand.BluetoothLE/Platforms/Windows/BluetoothDevice.windows.cs b/InTheHand.BluetoothLE/Platforms/Windows/BluetoothDevice.windows.cs index f544e15..3fe538c 100644 --- a/InTheHand.BluetoothLE/Platforms/Windows/BluetoothDevice.windows.cs +++ b/InTheHand.BluetoothLE/Platforms/Windows/BluetoothDevice.windows.cs @@ -15,7 +15,7 @@ namespace InTheHand.Bluetooth { - partial class BluetoothDevice + partial class BluetoothDevice : IDisposable { internal BluetoothLEDevice NativeDevice; internal readonly ConcurrentDictionary NativeDisposeList = new ConcurrentDictionary(); @@ -40,7 +40,7 @@ internal BluetoothDevice(BluetoothLEDevice device) ~BluetoothDevice() { - DisposeAllNativeObjects(); + Dispose(disposing: false); } /// Adds a native (IDisposable) object to the dispose list @@ -249,5 +249,25 @@ void DoUnwatchAdvertisements() _advertisementWatcher.Stop(); } }*/ + + private void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects) + } + + DisposeAllNativeObjects(); + disposedValue = true; + } + } + + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } } }