UWP. Trying to async download pictures and get System.Exception: Calling Async synchronously, 'marshalled for a different thread'

0

if interface need a picture it saves request in

ConcurrentDictionary<key, Delegate> 

and when picture is on the disk read it and SavedDelegate?.Invoke(key, byte[]). But there is an error in this place:

private async void OnDelegateInvokeAsync(ImageItem item, byte[] body)
{
...
item.Image = new BitmapImage();
...
}

System.Exception: Calling Async synchronously, 'marshalled for a different thread' message (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))'

What is the best way to resolve this problem?

multithreading
uwp
asked on Stack Overflow Nov 28, 2018 by user1820916 • edited Nov 28, 2018 by user1820916

1 Answer

1

You should change the image in the UI thread:

Dispatcher.Invoke( ()=> { item.Image = new BitmapImage(); ... } );
answered on Stack Overflow Nov 28, 2018 by Nick

User contributions licensed under CC BY-SA 3.0