Hi everybody,
I call MyPage with Navigation.PushAsync() from the MainPage. I have next code in MyPage's constructor:
public MyPage(IAdapter adapterin, IDevice devicein, string ChannelName)
{
InitializeComponent();
adapter = adapterin;
device = devicein;
LabelChannelName.Text = ChannelName;
adapter.DeviceConnectionLost += (s, e) =>
{
Debug.WriteLine($"LOST CONNECTION: {e.Device.Name}");
adapter.DeviceConnectionLost -= null;
Device.BeginInvokeOnMainThread(() =>
{
this.Navigation.PopAsync();
});
Debug.WriteLine($"LOST CONNECTION.");
};
}
When adapter.DeviceConnectionLost happens (for instance when I shut dowm my ble peripheral) MyPage closes correctly.
The second time I open MyPage if DeviceConnectionLost event happens then I get an Unhandled Exception, cause I guess PopAsync is reached twice. It seems that second PopAsync() generates the exception.
I have checked that if MyPage is loaded three times for example, ConnectionLost event will be executed three times, as I can see "LOST CONNECTION." text in my debug output window.
Is there any way to erase past events of MyPage after doing PopAsync ? How could I resolve this issue ?
Thanks in advance and best regards,
Asier.