Example #1
0
        /// <summary>
        /// Disconnects the band by disposing all references. Band will stay paired though.
        /// </summary>
        /// <param name="triggerEvent">Should the <see cref="DeviceConnectionChanged"/> event be triggered?</param>
        public void DisconnectBand(bool triggerEvent = true)
        {
            if (triggerEvent)
            {
                DeviceConnectionChanged?.Invoke(DeviceIndex, false);
            }

            DeviceConnectionChanged = null;
            _heartRate.Dispose();
            _authentication.Dispose();
            if (_connectedBtDevice != null)
            {
                _connectedBtDevice.ConnectionStatusChanged -= ConnectionStatusChanged;
                _connectedBtDevice.Dispose();
                _connectedBtDevice = null;
            }

            // Needed to force an immediate update of the connection-status by deleting the removed references.
            GC.Collect();
        }