1
votes

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();
    }
1

1 Answers

0
votes

This is strange. I dont think that this is a good answer. Its more a dirty coded workaround.

Using vs2015 debugging. It turned out that after i was properly closing the active streams. And de-registered properly my new colour and new depth frame events. Then next the app seamed to freeze on kinectsensor.stop() and on kinectsensor.Dispose(). Removing these stop(); and dispose(); commands, allowed the application close, although it takes pretty long to close say 10 sec or so, which seams strange to me

So by not closing this camera, it closes.. strange.

I don't think this is the recommended way so if someone knows how to do this the right way i'm all ears.