Is there a restriction on using a BitmapImage (or other UI namespace classes) on a none- UI thread?

0

I'm doing some cloud operations involving a BitmapImage in my code, and on the response (basically a none-UI thread for sure) I'm getting a "The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))" on -

BitmapImage cImage = new BitmapImage(); 

AFAK this means that I've tried to access the UI from a none-UI thread, but I'm just instantiating the thing, didn't try to modify any ui related data..

Any ideas as to why is this happening? Am I restricted from using a class that's defined in a UI namespace on none-UI threads?

c#
windows-store-apps
asked on Stack Overflow Aug 16, 2015 by Oyiwai • edited Aug 16, 2015 by Oyiwai

1 Answer

1

In Windows Runtime, the BitmapImage class inherits from the DependencyObject which will restrict the access from the non-UI thread. So you cannot manipulate the BitmapImage object in non-UI thread, as Aybe suggested, you need to use UI thread dispatcher.

answered on Stack Overflow Aug 17, 2015 by Jeffrey Chen

User contributions licensed under CC BY-SA 3.0