protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
// Remove local suspension handlers from the App since this page is no longer active.
App.Current.Suspending -= App_Suspending;
App.Current.Resuming -= App_Resuming;
// Make sure to stop the watcher when leaving the context. Even if the watcher is not stopped,
// scanning will be stopped automatically if the watcher is destroyed.
watcher.Stop();
// Always unregister the handlers to release the resources to prevent leaks.
watcher.Received -= OnAdvertisementReceived;
watcher.Stopped -= OnAdvertisementWatcherStopped;
base.OnNavigatingFrom(e);
}