/// <summary> /// Registers the pedometer background task with a step goal of 50 steps. /// </summary> private void RegisterBackgroundTask() { // build the background task with the known entry points for Pedometer background task var builder = new BackgroundTaskBuilder() { Name = SampleBackgroundTaskName, TaskEntryPoint = SampleBackgroundTaskEntryPoint }; // Get the current readings to find the current step counters var currentReadings = sensor.GetCurrentReadings(); stepCount = 0; foreach (PedometerStepKind kind in Enum.GetValues(typeof(PedometerStepKind))) { PedometerReading reading; if (currentReadings.TryGetValue(kind, out reading)) { stepCount += reading.CumulativeSteps; } } // set a new step goal stepGoal = stepCount + Scenario4_BackgroundPedometer.stepGoalOffset; // create a Pedometer data threshold for that step goal var threshold = new PedometerDataThreshold(sensor, stepGoal); // create a sensor trigger using the above threshold var trigger = new SensorDataThresholdTrigger(threshold); builder.SetTrigger(trigger); BackgroundTaskRegistration task = builder.Register(); task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted); backgroundTaskRegistered = true; UpdateUIAsync("Registered"); }