我一直在运行 Windows 10 IoT 核心版的 Raspberry Pi 2 中开展项目。项目对象传感器通过打开视频触发。 但是我收到以下错误:
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
调用包含在调度程序同步中,如本文所述:UWP update UI from Task
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
VideoAc();
});
关于c# - Windows 10 IoT Core - 视频打开关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38425955/