G
Greg Duncan
Guest
Todays project by Marcus Kohnert brings us back to the FluentKinect and Marcus recent update to make it awaitable...
await GetKinect()
In the first blog post about FluentKinect I’ve mentioned that I’m not very happy with the actual process of getting a KinectSensor instance from the KinectSensors collection.
FluentKinect has now been updated and the KinectConnector’s static method GetKinect is now awaitable.
var kinect = await KinectConnector.GetKinect();
kinect.Start();
It’s not thread safe at the moment but there are a few improvements now in my opinion.
Project Information URL: http://passiondev.wordpress.com/2013/07/30/await-getkinect/
Project Download URL: http://www.nuget.org/packages/FluentKinect
Project Source URL: https://github.com/MarcusKohnert/FluentKinect
public static Task<KinectSensor> GetKinect()
{
return Task.Factory.StartNew<KinectSensor>(() =>
{
if (kinectSensor != null) return kinectSensor;
var kinect = KinectSensor.KinectSensors
.FirstOrDefault(_ => _.Status == KinectStatus.Connected);
if (kinect != null)
{
kinectSensor = kinect;
return kinectSensor;
}
using (var signal = new ManualResetEventSlim())
{
KinectSensor.KinectSensors.StatusChanged += (s, e) =>
{
if (e.Status == KinectStatus.Connected)
{
kinectSensor = e.Sensor;
coordinateMapper = new CoordinateMapper(kinectSensor);
signal.Set();
}
};
signal.Wait();
}
return kinectSensor;
});
}
Contact Information:
Continue reading...
await GetKinect()
In the first blog post about FluentKinect I’ve mentioned that I’m not very happy with the actual process of getting a KinectSensor instance from the KinectSensors collection.
FluentKinect has now been updated and the KinectConnector’s static method GetKinect is now awaitable.
var kinect = await KinectConnector.GetKinect();
kinect.Start();
It’s not thread safe at the moment but there are a few improvements now in my opinion.
- You can start and debug your actual program without a Kinect controller connected because no more exception is thrown. This helps with Kinect programming on a plane for example.
- Your program starts faster because GetKinect returns immediately
- Since GetKinect returns a Task you get the ability to await the result
- You can start and debug your actual program without a Kinect controller connected because no more exception is thrown. This helps with Kinect programming on a plane for example.
Project Information URL: http://passiondev.wordpress.com/2013/07/30/await-getkinect/
Project Download URL: http://www.nuget.org/packages/FluentKinect
Project Source URL: https://github.com/MarcusKohnert/FluentKinect
public static Task<KinectSensor> GetKinect()
{
return Task.Factory.StartNew<KinectSensor>(() =>
{
if (kinectSensor != null) return kinectSensor;
var kinect = KinectSensor.KinectSensors
.FirstOrDefault(_ => _.Status == KinectStatus.Connected);
if (kinect != null)
{
kinectSensor = kinect;
return kinectSensor;
}
using (var signal = new ManualResetEventSlim())
{
KinectSensor.KinectSensors.StatusChanged += (s, e) =>
{
if (e.Status == KinectStatus.Connected)
{
kinectSensor = e.Sensor;
coordinateMapper = new CoordinateMapper(kinectSensor);
signal.Set();
}
};
signal.Wait();
}
return kinectSensor;
});
}
Contact Information:
- Blog: http://passiondev.wordpress.com
- Twitter: @MarcusKohnert
Continue reading...