问题描述
我创建了大约10个执行相同工作的线程-从Internet下载图像.下载完成后,它将引发以下回调函数:
I create about 10 threads doing the same work - downloading image from the Internet. After the download is completed it will raise this callback function:
private void DownloadImageWrapper(IRestResponse response, params object[] args)
{
byte[] imageData = response.RawBytes;
using (Stream ms = new MemoryStream(imageData))
{
WriteableBitmap wbImg = PictureDecoder.DecodeJpeg(ms);
callback.DynamicInvoke(wbImg, file);
};
}
该异常与WriteableBitmap一起抛出.我读到锁将对此有所帮助,但找不到关于应该"锁定的内容的任何信息.有人帮忙吗?
The exception is thrown in line with WriteableBitmap. I read that lock will help with this, but couldn't find anything about "what" I should lock there. Anyone would help?
推荐答案
需要在UI线程上创建WriteableBitmap.
WriteableBitmap needs to be created on the UI thread.
您将必须将所有照片保留为像素阵列(整数或字节),然后稍后在完成后在UI线程上创建WriteableBitmaps.
You will have to keep all your photos as arrays of pixels (ints or bytes) and then create WriteableBitmaps later, after you're done, on the UI thread.
这篇关于具有多个线程时出现WriteableBitmap异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!