gpt4 book ai didi

c# - 从 Microsoft Band 获取心率

转载 作者:太空狗 更新时间:2023-10-29 23:30:24 26 4
gpt4 key购买 nike

我正在尝试从 Microsoft Band 获取心率。只要值发生变化,它就应该更新。然后我试图在 TextBlock 中显示该值。我首先创建了一个 IBandClient 实例,并像这样设置它的 HeartRate.ReadingChanged 方法:

bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;

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

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

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));

TextBlock 文本然后绑定(bind)到 HeartRate。但是,我在尝试设置 HeartRate 时不断收到此错误:

The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

我的猜测是它正在尝试设置 HeartRate,而之前的调用仍在设置它。

最佳答案

尝试实现它,看看效果如何,如果您仍然需要 int 变量,则在文本 block 中显示它时将其转换回字符串。

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

关于c# - 从 Microsoft Band 获取心率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31215873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com