async void watcher_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { watcher.Stop(); await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { await Task.Delay(5000); var viewModel = new MainPageViewModel(); await viewModel.Init(); this.ViewModel = viewModel; }); }
/// <summary> /// Invoked when a connection is established to the Bluetooth device /// </summary> /// <param name="sender">The watcher object that sent the notification</param> /// <param name="args">The updated device object properties</param> private async void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { var connectedProperty = args.Properties["System.Devices.Connected"]; bool isConnected = false; if ((deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) && isConnected) { var status = await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync( CHARACTERISTIC_NOTIFICATION_TYPE); if (status == GattCommunicationStatus.Success) { IsServiceInitialized = true; // Once the Client Characteristic Configuration Descriptor is set, the watcher is no longer required watcher.Stop(); watcher = null; } // Notifying subscribers of connection state updates if (DeviceConnectionUpdated != null) { DeviceConnectionUpdated(isConnected); } } }