I'm using Kinect in a WPF app and Dan Fernández taught us in his quickstart video series how to stop the sensor when calling the event "Window_Closing" (which being new into C#, I guess it's a delegate, or event handler). The thing is that if I press the Stop button in the Visual Studio UI to stop running, my Kinect doesn't stop and then I have to run the app again and close it clicking on the X button.
Is there a more general way to stop the Kinect with some event for the app Shutdown inside my code?
Thank you.
void StopKinect(KinectSensor sensor) {
if (sensor != null) {
sensor.Stop();
if (sensor.AudioSource != null)
{
sensor.AudioSource.Stop();
}
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
StopKinect(kinectSensorChooser1.Kinect);
}