I am trying to crop an image from a Run method from Windows 10 app (UWP) IBackgroundTask. To achive that I'm using the WriteableBitmapEx but at the moment that I try to instantiate a new object, I got the exception:
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
I have tried to use some Dispatchers but other exception ocurred. Any idea?
WriteableBitmap
is a UI object, and requires UI thread, which background task lacks of.
Depending on your needs, you can either use different API to work with images (check this topic for BitmapEncoder
) or derive your background task from XamlRenderingBackgroundTask, which will call its OnRun method in UI thread. Although keep in mind, that it's recommended to use C++ in XamlRenderingBackgroundTask due to memory limitations.
User contributions licensed under CC BY-SA 3.0