UWP ObservableCollection (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

0

I need for some reason to use ObservableCollection in a thread other than the UI thread. Is it possible ?

I have this error:

The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

at this line:

observableCollection.Add(new RfcommChatDeviceDisplay(deviceInfo));
c#
uwp
asked on Stack Overflow Sep 28, 2019 by Pol Poggi • edited Sep 28, 2019 by pappbence96

1 Answer

0

It is possible to explicitly request the UI thread to be used:

CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    // Your code goes here
});

This will run the inner block on the UI thread so you can update the UI from there.

answered on Stack Overflow Sep 28, 2019 by pappbence96

User contributions licensed under CC BY-SA 3.0