从微软乐队获得心率

5 c# windows-phone-8.1 microsoft-band

我试图从微软乐队获得心率.只要值发生变化,它就应该更新.然后我试图在a中显示该值TextBlock.我首先创建一个实例IBandClient,并设置其HeartRate.ReadingChanged方法如下:

bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
Run Code Online (Sandbox Code Playgroud)

然后我尝试像这样更新值:

private void HeartRate_ReadingChanged(object sender, Microsoft.Band.Sensors.BandSensorReadingEventArgs<Microsoft.Band.Sensors.IBandHeartRateReading> e)
{
    HeartRate = e.SensorReading.HeartRate;
}
Run Code Online (Sandbox Code Playgroud)

HeartRate是这样的一int组:

public int HeartRate
{
    get { return (int)GetValue(HeartRateProperty); }
    set { SetValue(HeartRateProperty, value); }
}

// Using a DependencyProperty as the backing store for HeartRate.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty HeartRateProperty =
    DependencyProperty.Register("HeartRate", typeof(int), typeof(MainPage), new PropertyMetadata(0));
Run Code Online (Sandbox Code Playgroud)

TextBlock随后的文字必然HeartRate.但是,我在尝试设置时不断收到此错误HeartRate:

该应用程序调用了一个为不同线程编组的接口.(来自HRESULT的异常:0x8001010E(RPC_E_WRONG_THREAD))

我的猜测是它正在尝试设置,HeartRate而它仍然是从之前的通话中设置的.

Eug*_*nic 3

尝试实现这个并看看它是如何进行的,如果您仍然想要 int 变量,那么在文本块中显示它时将其转换回字符串。

await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, 
               () => 
               {
                   Textblock.Text =  e.SensorReading.HeartRate.ToString())
               }).AsTask();
Run Code Online (Sandbox Code Playgroud)