Uwp Windows10 IoT内核线程错误

Uwp Windows10 IoT内核线程错误,uwp,gpio,windows-iot-core-10,dragonboard,Uwp,Gpio,Windows Iot Core 10,Dragonboard,我是Windows10物联网的新手 我将用DragonBoard 410c作为白板应用程序进行应用 我将按钮连接到GPIO 编码如下,但发生了错误 private void InitGPIO() { var gpio=GpioController.GetDefault(); 如果(gpio==null) { var dialog2=新消息对话框(“请检查GPIO”); dialog2.ShowAsync(); 返回; } BTN\U UP=gpio.OpenPin(BTN\U UP\U编号);

我是Windows10物联网的新手

我将用DragonBoard 410c作为白板应用程序进行应用

我将按钮连接到GPIO

编码如下,但发生了错误

private void InitGPIO()
{
var gpio=GpioController.GetDefault();
如果(gpio==null)
{
var dialog2=新消息对话框(“请检查GPIO”);
dialog2.ShowAsync();
返回;
}
BTN\U UP=gpio.OpenPin(BTN\U UP\U编号);
BTN_UP.SetDriveMode(GpioPinDriveMode.Input);
BTN_UP.DebounceTimeout=时间跨度(从毫秒开始)(50);
BTN_UP.ValueChanged+=BTN_UP\u push;
var dialog=newmessagedialog(“GPIO就绪”);
dialog.showsync();
}
私有无效btn向上推送(GpioPin发送方,GPIOPValigueChangedEventArgs e)
{
int但_宽度=0;
int但_高度=0;
但是_width=(int)cutButton.width;
但是_height=(int)cutButton.height;

}
由于您在非UI线程中访问UI元素(cutButton是按钮对吗?),因此会出现以下异常

您需要将线程从当前执行线程封送到UI线程

Windows.UI.Core.CoreDispatcher可用于此操作。以下是一个例子:

using Windows.ApplicationModel.Core;

    private async void btn_up_pushed(GpioPin sender, GpioPinValueChangedEventArgs e)
    {
        int but_width = 0;
        int but_height = 0;

        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
            but_width = (int)cutButton.Width;
            but_height = (int)cutButton.Height;
        });
    }

Ref:“

非常感谢。我根据你的建议解决了这个问题。