public void OnDisappearing()
 {
     if (Characteristic.CanUpdate)
     {
         Characteristic.StopUpdates();
     }
 }
Esempio n. 2
0
        private Task <byte[]> GetCharacteristicValue(
            ICharacteristic characteristic)
        {
            var taskCompletionSource = new TaskCompletionSource <byte[]>();

            EventHandler <CharacteristicReadEventArgs> handler = null;

            handler = (sender, args) =>
            {
                Platform.Current.RunOnMainThread(() =>
                {
                    characteristic.ValueUpdated -= handler;
                    characteristic.StopUpdates();
                    if (!taskCompletionSource.Task.IsCompleted)
                    {
                        taskCompletionSource.SetResult(
                            args.Characteristic.Value);
                    }
                });
            };

            characteristic.ValueUpdated += handler;
            characteristic.StartUpdates();

            return(taskCompletionSource.Task);
        }
 protected override void OnDisappearing()
 {
     base.OnDisappearing();
     if (characteristic.CanUpdate)
     {
         characteristic.StopUpdates();
     }
 }
Esempio n. 4
0
 protected override void OnDisappearing()
 {
     base.OnDisappearing();
     if (characteristic.CanUpdate)
     {
         characteristic.StopUpdates();
         characteristic.ValueUpdated -= valueUpdatedHandler;
     }
 }
        private async Task _disconnect()
        {
            try
            {
                _characteristicHR.ValueUpdated -= CharacteristicHR_ValueUpdated;
                _characteristicHR.StopUpdates();

                await _adapter.DisconnectDeviceAsync(_device);

                _connectionRetry            = 0;
                _device                     = null;
                _serviceHR                  = null;
                _serviceBattery             = null;
                _characteristicHR           = null;
                _characteristicBatteryLevel = null;
                _currentValue               = null;

                _log("_disconnect", "disconnected");
            }
            catch (Exception e)
            {
                _log("_disconnect", e.Message);
            }
        }
Esempio n. 6
0
 public void StopUpdates() => _characteristic.StopUpdates();