【发布时间】:2014-12-31 09:30:27
【问题描述】:
我必须在新线程中显示图像序列,否则 kinect 会因操作的复杂性而丢失帧。我试过了:
using (BodyFrame bodyframe = e.FrameReference.AcquireFrame())
{
if (bodyframe != null)
{
if (this.bodies == null)
{
this.bodies = new Body[bodyframe.BodyCount];
}
//the first time getandrefreshbodydata is called, kinect will allocate each body in the array.
//as long as those body objects are not disposed and not set to null in the array,
//those body objects will be re-used.
bodyframe.GetAndRefreshBodyData(this.bodies);
dataReceived = true;
}
else Console.WriteLine();
}
BodyCustom[] bodiesCustom = deserialize(directoryTxt[frameCount]);
sw.WriteLine("Frame " + frameCount);
if (dataReceived)
{
sw.WriteLine(dataReceived);
ThreadPool.QueueUserWorkItem(showImage, frameCount);
..............
还有:
private void showImage(Object frameCount)
{
imageReference.Source = new BitmapImage(new Uri(@directoryJpg[(int)frameCount]));
}
但我有
An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll
Additional information: Unable to access the object from the calling thread because that object is owned by another thread.
我认为错误取决于对象 imageReference,因为我在其他地方使用它,但也通过评论它我得到了这个错误。为什么?
我正在使用图像类 (System.Windows.Controls)
【问题讨论】:
-
UI 技术(wpf 或 winforms)??
-
是的,我使用 wpf 和 xaml
-
你需要用英文发布错误
-
我的帖子还没解决
标签: c# multithreading exception threadpool kinect