I'm using kinect SDK 1.7 (since only that one works on win 7).
My program works fine, i can change video modes for depth and color without errors. But it goes wrong when i want to close my program by using the top right redcross close main form corner button. In fact it seams even if i set breakpoint in Deactivate Sensor, ..its never triggered ??
I wrote code below with no success.
private void DeActivateSensor()
{
if (kinectSensor != null)
{
if (kinectSensor.SkeletonStream.IsEnabled) { kinectSensor.SkeletonStream.Disable();}
if (kinectSensor.ColorStream.IsEnabled) { kinectSensor.ColorStream.Disable(); }
if (kinectSensor.DepthStream.IsEnabled) {kinectSensor.DepthStream.Disable();}
Thread.Sleep(1000);
kinectSensor.ColorFrameReady -= new EventHandler<ColorImageFrameReadyEventArgs>(kinectSensor_ColorFrameReady);
kinectSensor.DepthFrameReady -= new EventHandler<DepthImageFrameReadyEventArgs>(kinectSensor_DepthFrameReady);
// since i dont have skelleton events i dont need to repeat that for it
try
{
if (kinectSensor.IsRunning) { kinectSensor.Stop(); }
}
catch
{
Debug.WriteLine("unknown Exception ");
}
Thread.Sleep(1000);
if (kinectSensor != null) { kinectSensor.Dispose(); }
}
}
private void MainForm_Load(object sender, EventArgs e)
{
DeActivateSensor();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
DeActivateSensor();
}