【发布时间】:2015-01-22 14:30:43
【问题描述】:
这是我的例外
The calling thread cannot access this object because a different thread owns it.
我的函数从计算中得到结果,我想更新一个已经打开的窗口..
public override void UpdateResult(BaseMetricResults result)
{
var newResults = result as MetricUniformityResults;
if (newResults == null)
{
return;
}
DispatcherHelper.UIDispatcher.Invoke(() =>
{
TopToBottomGraph.CrossSectionPoints.Clear();
foreach (var point in newResults.TopToBottomGraph.CrossSectionPoints)
{
TopToBottomGraph.CrossSectionPoints.Add(point);
}
newResults.JetMap.Freeze(); //exception here
byte[] arr = new byte[(int) (newResults.JetMap.Width*newResults.JetMap.Height*3)];
newResults.JetMap.CopyPixels(arr, (int) (newResults.JetMap.Width*3), 0);
JetMap = BitmapSource.Create((int) newResults.JetMap.Width, (int) newResults.JetMap.Height, 96, 96,
PixelFormats.Rgb24, BitmapPalettes.WebPalette, arr,
(int) (newResults.JetMap.Width*3));
});
}
这是我最后一次尝试我不确定是否必须冻结位图源...
无论如何 newResults.JetMap 是 BitmapSource,我有一个名为 JetMap 的属性,它是新的 BitmapSource,如何用新的图像更新旧图像?
【问题讨论】:
-
异常究竟发生在哪里?哪种说法?
-
@Clemens newResults.JetMap.Freeze();
-
如果您在 SO 中搜索您收到的错误消息,您将获得大约 400 个可能的答案,所有这些都提供了大致相同的指导:使用
Dispatcher.Invoke()。如果您的场景需要不同的东西,您需要提供一个足够详细的问题,包括a complete code example 和清晰、准确的描述为什么它需要不同的东西。 -
@PeterDuniho 我认为你错了,我只是在滥用函数 freeze(),你可以看到它已经解决了。
标签: c# wpf bitmapsource