c# - Windows 10 IoT Core - 视频打开关闭

标签 c# windows raspberry-pi2 windows-iot-core-10

我一直在运行 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/

相关文章:

python - 有没有办法在SSD上写入,如果在写入过程中断开连接,数据不会丢失?

c# - 确定反射场是否易变

c# - 在 OnActionExpandListener 上找不到符号

c++ - 如何捕获来自另一个进程的退出消息?

linux - 无法从我的 Raspberry Pi B+ V2 的互联网打开 apache 网站

ios - 从 Raspberry Pi 到 iPhone 的实时数据

c# - 如何使用 Entity Framework Core 2.0 检索 JSON 存储过程的结果?

c# - 我应该在我的代码隐藏或 BusinessLogic 类中使用此功能

c++ - 根据 VID/PID 查找并弹出 USB 设备

windows - Windows 7 登录屏幕中是否有本地机器名称的别名?