简体   繁体   中英

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

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?

您应该在UI线程中更改图像:

Dispatcher.Invoke( ()=> { item.Image = new BitmapImage(); ... } );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM