i must show sequence of image in a new thread because otherwise kinect lost frame for the complexity of operations. I have tried so:
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);
..............
And:
private void showImage(Object frameCount)
{
imageReference.Source = new BitmapImage(new Uri(@directoryJpg[(int)frameCount]));
}
but i have
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.
I think that the error depends on the object imageReference because i use it elsewhere, but also by commenting it i obtain this error. Why?
I'm using Image Class (System.Windows.Controls)