private void Dispose(bool disposing)
{
bool needToStopStatusThread = false;
lock ( openDevices )
{
// decrease reference counter and check if we need to close the device
if (--openDevices[deviceID].ReferenceCounter == 0)
{
if (!openDevices[deviceID].DeviceFailed)
{
KinectNative.freenect_close_device(rawDevice);
}
openDevices.Remove(deviceID);
}
needToStopStatusThread = (openDevices.Count == 0);
}
rawDevice = IntPtr.Zero;
if (needToStopStatusThread)
{
StopStatusThread( );
}
}