Windows 10 IoT Core - video open close

2

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;
}
c#
windows
raspberry-pi2
windows-iot-core-10
asked on Stack Overflow Jul 17, 2016 by Hakan Kaya • edited Jul 18, 2016 by Hakan Kaya

1 Answer

3

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();
});
answered on Stack Overflow Jul 18, 2016 by Mario Vernari • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0