2021-11-28

INotifyPropertyChanged Resubscribe not working, only the first time subscription working

I developing a Xamarin application, and I communicating an external custom device. My problem is very strange, firstly the application starting, and connecting automatically to device, so everything is fine. When i suddenly remove the battery from the external device, the bluetooth connection is broken, and it's working fine to, but when I turn on the external device again, my Xamarin application connecting to it very well well, but the subscriptions not working anymore.

I debugged it, but not calling anymore. I think the unsubscribe/subscribe process is wrong.

...
if (ble.GetConnectionStatus())
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    ...
                    
                    ble.Adapter.DeviceConnectionLost -= Adapter_DeviceConnectionLost;
                    ble.Adapter.DeviceConnectionLost += Adapter_DeviceConnectionLost;
                    ble.PropertyChanged -= Ble_PropertyChanged;
                    ble.PropertyChanged += Ble_PropertyChanged;
                    data.PropertyChanged -= data_PropertyChanged;
                    data.PropertyChanged += data_PropertyChanged;
                    ...
                });
...

So it's so strange, because first time this working, when starting the app, but when I call it after reconnect that same subscription not working. So if its wrong, then why working this at very first time?

I have no error, just not fire the functions again after resubscribe.

So as you see, I need to "refresh" the subscription. Is there another way to solve this problem?



from Recent Questions - Stack Overflow https://ift.tt/3l68fuT
https://ift.tt/eA8V8J

No comments:

Post a Comment