Windows 10 IoT Core - video open close

2019-07-08 05:09发布

问题:

I've been working project in Raspberry Pi 2 running Windows 10 IoT Core. Project subject sensor triggering with open a video. But I am getting the following error:

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

Code:

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

回答1:

Likely the sensor event comes from a different thread than the UI's one, and that gets the framework angry.

Try to enclose the VideoAc call in a dispatcher synchronization as explained in this piece: UWP update UI from Task

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