Windows 10 个物联网核心 - 视频打开关闭

Windows 10 IoT Core - video open close

我一直在 Raspberry Pi 2 运行 Windows 10 IoT Core 项目中工作。项目对象传感器通过打开视频触发。 但我收到以下错误:

An exception of type 'System.Exception' occurred in ProjeVol1.exe but was not handled in user code

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

代码:

private void SensorPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
{
    Debug.WriteLine("Sensor Tetiklendi");
    if (args.Edge == GpioPinEdge.FallingEdge)
    {
        Debug.WriteLine("Falling Edge");
        ledPin.Write(GpioPinValue.High);
        VideoAc();

    }
    else if (args.Edge == GpioPinEdge.RisingEdge)
    {
        Debug.WriteLine("Rising Edge");
        ledPin.Write(GpioPinValue.High);

    }
}


public void VideoAc()
{
    video.AutoPlay = true;
    video.Play();
    video.MediaEnded += Video_MediaEnded;
}

可能传感器事件来自与 UI 不同的线程,这会激怒框架。

尝试将 VideoAc 调用包含在调度程序同步中,如本文所述:

await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
    VideoAc();
});