//--------------------------------------------------------------------- // Method to handle if/when the publisher's status changes //--------------------------------------------------------------------- // Event callback for when the status of the publisher changes. This // helps keep the publisher going if it is aborted by the system. private void OnPublisherStatusChanged( BluetoothLEAdvertisementPublisher publisher, BluetoothLEAdvertisementPublisherStatusChangedEventArgs eventArgs ) { if (eventArgs.Status == BluetoothLEAdvertisementPublisherStatus.Aborted) { Debug.WriteLine("Advertisemen publisher aborted. Restarting."); publisher.Start(); } }
/// <summary> /// Invoked as an event handler when the status of the publisher changes. /// </summary> /// <param name="publisher">Instance of publisher that triggered the event.</param> /// <param name="eventArgs">Event data containing information about the publisher status change event.</param> private async void OnPublisherStatusChanged( BluetoothLEAdvertisementPublisher publisher, BluetoothLEAdvertisementPublisherStatusChangedEventArgs eventArgs) { // This event handler can be used to monitor the status of the publisher. // We can catch errors if the publisher is aborted by the system BluetoothLEAdvertisementPublisherStatus status = eventArgs.Status; BluetoothError error = eventArgs.Error; StatusChanged?.Invoke(publisher, eventArgs); }
/// <summary> /// Invoked as an event handler when the status of the publisher changes. /// </summary> /// <param name="publisher">Instance of publisher that triggered the event.</param> /// <param name="eventArgs">Event data containing information about the publisher status change event.</param> private async void OnAdvertiserStatusChanged( BluetoothLEAdvertisementPublisher publisher, BluetoothLEAdvertisementPublisherStatusChangedEventArgs eventArgs) { // This event handler can be used to monitor the status of the publisher. // We can catch errors if the publisher is aborted by the system BluetoothLEAdvertisementPublisherStatus status = eventArgs.Status; BluetoothError error = eventArgs.Error; if (error == BluetoothError.Success) { setStatus(status.ToString()); switch (status) { case BluetoothLEAdvertisementPublisherStatus.Started: setStatus("Connecting..."); try { var connectionTask = this.AncsManager.Connect(); var connectionResult = await connectionTask; //var connectionResult = await this.AncsManager.Connect(); if (connectionResult == true) { setStatus("Waiting for device..."); } else { setStatus("No suitable device"); } } catch (Exception ex) { setStatus(ex.Message); } break; } } else { setStatus(String.Format("Error: {0}", error.ToString())); } }
/// <summary> /// Invoked as an event handler when the status of the publisher changes. /// </summary> /// <param name="publisher">Instance of publisher that triggered the event.</param> /// <param name="eventArgs">Event data containing information about the publisher status change event.</param> private async void OnPublisherStatusChanged( BluetoothLEAdvertisementPublisher publisher, BluetoothLEAdvertisementPublisherStatusChangedEventArgs eventArgs) { // This event handler can be used to monitor the status of the publisher. // We can catch errors if the publisher is aborted by the system BluetoothLEAdvertisementPublisherStatus status = eventArgs.Status; BluetoothError error = eventArgs.Error; // Update the publisher status displayed in the sample // Serialize UI update to the main UI thread await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { PublisherStatusBlock.Text = string.Format("Published Status: {0}, Error: {1}", status.ToString(), error.ToString()); }); }
private void Publisher_StatusChanged(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { Debug.WriteLine(args.Status); Debug.WriteLine(args.Error); lock (lockObject) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { switch (args.Status) { case BluetoothLEAdvertisementPublisherStatus.Waiting: TransitionToStarting.Begin(); state = DisplayStates.Wait; break; case BluetoothLEAdvertisementPublisherStatus.Started: TransitionToBroad.Begin(); state = DisplayStates.Good; break; case BluetoothLEAdvertisementPublisherStatus.Stopping: TransitionToStarting.Begin(); state = DisplayStates.Wait; break; case BluetoothLEAdvertisementPublisherStatus.Stopped: Stop.Begin(); state = DisplayStates.Done; break; case BluetoothLEAdvertisementPublisherStatus.Created: break; case BluetoothLEAdvertisementPublisherStatus.Aborted: TransitionToError.Begin(); state = DisplayStates.Error; break; } Status.Text = args.Status.ToString(); }).AsTask().Wait(); } }
private static void Publisher_StatusChanged(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { var sb = new StringBuilder(); sb.AppendLine($"Handler: {nameof(Publisher_StatusChanged)}"); sb.AppendLine($"Status: {args.Status.ToString()}"); sb.AppendLine($"Error: {args.Error.ToString()}"); sb.AppendLine($"----------------------------------"); Console.WriteLine(sb.ToString()); }
protected void publisherStatusChangeHandler(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { m_logger.WriteLine("Advertisement publisher status changed to " + args.Status); }
private async void OnPublisherStatusChangedAsync(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { System.Diagnostics.Debug.WriteLine("Bluetooth LE Advertisement Publisher status changed to " + args.Status); if (args.Status == BluetoothLEAdvertisementPublisherStatus.Aborted) { // Aborted status most likely means that Bluetooth is not enabled (i.e. turned off) MessageDialog messageDialog = new MessageDialog("Bluetooth LE Advertisement Publisher aborted. Make sure you have Bluetooth turned on on your device and try again."); await messageDialog.ShowAsync(); } IsPublisherStarted = (args.Status == BluetoothLEAdvertisementPublisherStatus.Started); }); }
private void Publisher_StatusChanged(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { Debug.WriteLine(args.Status.ToString()); }
private async void OnPublisherStatusChangedAsync(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { System.Diagnostics.Debug.WriteLine("Bluetooth LE Advertisement Publisher status changed to " + args.Status); if (args.Status == BluetoothLEAdvertisementPublisherStatus.Aborted) { // Aborted status most likely means that Bluetooth is not enabled (i.e. turned off) MessageDialog messageDialog = new MessageDialog("Bluetooth LE Advertisement Publisher aborted. Make sure you have Bluetooth turned on on your device and try again."); await messageDialog.ShowAsync(); } IsPublisherStarted = (args.Status == BluetoothLEAdvertisementPublisherStatus.Started); }); }
private void OnPublisherStatusChanged(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { Debug.WriteLine("Advertisement publisher status changed: " + sender.Status + ", Error: " + args.Error); }
private void Publisher_StatusChanged(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { if (args.Status == BluetoothLEAdvertisementPublisherStatus.Started) { if (!isPublishing) { isPublishing = true; OnPropertyChanged("IsPublishing"); } IsReady = true; } else if (args.Status == BluetoothLEAdvertisementPublisherStatus.Stopped || args.Status == BluetoothLEAdvertisementPublisherStatus.Aborted) { if (isPublishing) { isPublishing = false; OnPropertyChanged("IsPublishing"); } IsReady = true; } }
private async void Publisher_StatusChanged(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { if (args.Error != Windows.Devices.Bluetooth.BluetoothError.Success) { await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { MessageDialog dialog = new MessageDialog("Error: " + args.Error.ToString(), "Can not start Watcher"); await dialog.ShowAsync(); }); } }
private async void Publisher_StatusChanged(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) { if (args.Error != Windows.Devices.Bluetooth.BluetoothError.Success) { await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { MessageDialog dialog = new MessageDialog("Error: " + args.Error.ToString(), "Can not start Watcher"); await dialog.ShowAsync(); }); } }