updating UI element after gpio button press

0

I'm making an application that updates a UI element after a press on a button connected to the GPIO pins. it's my first time working with windows iot core. I thought it would be as easy as this "lblQuestion.Text = "Button works!";" but it isn't. can anyone tell me what I have to add for it to work correctly?

I'm recieving this error: System.Exception: 'The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))'

c#
raspberry-pi3
windows-iot-core-10

1 Answer

1

Please use following code to to marshal calls coming from non-UI threads.

        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            lblQuestion.Text = "Button works!
        });

This document describes the reason why you need to create a DependencyObject on a UI thread.

answered on Stack Overflow Feb 10, 2020 by Michael Xu - MSFT

User contributions licensed under CC BY-SA 3.0