public async void Run(IBackgroundTaskInstance taskInstance) { System.Diagnostics.Debug.WriteLine("WE are @ Background"); _deferral = taskInstance.GetDeferral(); _taskInstance = taskInstance; _taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled); GattCharacteristicNotificationTriggerDetails details = (GattCharacteristicNotificationTriggerDetails)taskInstance.TriggerDetails; //get the characteristics data and get heartbeat value out from it byte[] ReceivedData = new byte[details.Value.Length]; DataReader.FromBuffer(details.Value).ReadBytes(ReceivedData); HeartbeatMeasurement tmpMeasurement = HeartbeatMeasurement.GetHeartbeatMeasurementFromData(ReceivedData); System.Diagnostics.Debug.WriteLine("Background heartbeast values: " + tmpMeasurement.HeartbeatValue); // send heartbeat values via progress callback _taskInstance.Progress = tmpMeasurement.HeartbeatValue; //update the value to the Tile LiveTile.UpdateSecondaryTile("" + tmpMeasurement.HeartbeatValue); //Check if we are within the limits, and alert by starting the app if we are not alertType alert = await checkHeartbeatLevels(tmpMeasurement.HeartbeatValue); _deferral.Complete(); }
private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { LiveTile.UpdateSecondaryTile("--"); System.Diagnostics.Debug.WriteLine("Background " + sender.Task.Name + " Cancel Requested because " + reason); if (!reason.Equals(BackgroundTaskCancellationReason.Abort)) { ToastHelper.PopToast("Background Cancelled", "Background Task Cancelled, reason: " + reason + ", please re-start the applications."); } }