Skip to content

Commit

Permalink
Properly attach / detach events when the characteristic is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe authored and michael-hawker committed Oct 11, 2022
1 parent c9895b2 commit cadc08b
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ public ObservableGattCharacteristics(GattCharacteristic characteristic, Observab
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
ReadValueAsync();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

characteristic.ValueChanged += Characteristic_ValueChanged;
}

/// <summary>
Expand All @@ -152,6 +150,16 @@ public GattCharacteristic Characteristic
{
if (_characteristic != value)
{
if (value is not null)
{
value.ValueChanged += Characteristic_ValueChanged;
}

if (_characteristic is not null)
{
_characteristic.ValueChanged -= Characteristic_ValueChanged;
}

_characteristic = value;
OnPropertyChanged();
}
Expand Down

0 comments on commit cadc08b

Please sign in to comment.