【发布时间】:2012-09-08 02:20:42
【问题描述】:
我在 WPF 应用程序中使用 Kinect,Dan Fernández 在他的快速入门视频系列中教我们如何在调用事件“Window_Closing”(这是 C# 中的新功能,我猜它是委托或事件处理程序)时停止传感器)。问题是,如果我在 Visual Studio UI 中按下停止按钮停止运行,我的 Kinect 不会停止,然后我必须再次运行应用程序并单击 X 按钮将其关闭。
有没有更通用的方法来通过我的代码中的应用程序关闭事件来停止 Kinect?
谢谢。
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);
}
【问题讨论】:
-
我没有 C# 经验,但调试器退出时可能不会调用 Window_Closing。如果您根据以下内容覆盖 onClosing 事件会发生什么:stackoverflow.com/questions/5774849/…?在这种情况下会调用它吗?
-
不,鲍勃,这没什么区别。我也是 C# 的新手,我不知道哪个是该事件的方法(单击 VS 的停止按钮的事件。谢谢