/// <summary> /// Register to be notified when a connection is established to the Bluetooth device /// </summary> private void StartDeviceConnectionWatcher() { watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { "System.Devices.Connected" }, String.Empty); watcher.Updated += DeviceConnection_Updated; watcher.Start(); }
private void StartDeviceConnectionWatcher() { watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { "System.Devices.Connected" }, String.Empty); Log("Registering device connection watcher updated event handler"); watcher.Updated += DeviceConnection_Updated; Log("Starting device connection watcher"); watcher.Start(); }
async Task <bool> RegisterForConnectionEvents() { UnregisterForConnectionEvents(); string deviceContainerId = "{" + DeviceContainerId + "}"; PnpObject containerPnpObject = await PnpObject.CreateFromIdAsync(PnpObjectType.DeviceContainer, deviceContainerId, new string[] { CONNECTED_FLAG_PROPERTY_NAME }); var connectedProperty = containerPnpObject.Properties[CONNECTED_FLAG_PROPERTY_NAME]; bool isConnected = false; Boolean.TryParse(connectedProperty.ToString(), out isConnected); _connectionWatcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { CONNECTED_FLAG_PROPERTY_NAME }, String.Empty); _connectionWatcher.Updated -= DeviceConnection_Updated; _connectionWatcher.Updated += DeviceConnection_Updated; _connectionWatcher.Start(); return(isConnected); }
private void StartDeviceConnectionWatcher() { _watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { ConnectedProperty }, String.Empty); _watcher.Updated += DeviceConnection_Updated; _watcher.Start(); }