1
我使用的是kinect SDK 1.7(因爲只有那個可以在win 7上運行)。無法停止kinect相機凍結我的應用程序
我的程序工作正常,我可以改變視頻模式的深度和顏色沒有錯誤。但是當我想通過使用右上角的redcross關閉主窗體角落按鈕來關閉我的程序時出錯了。事實上,即使我在Deactivate Sensor中設置斷點,它也會接縫,..它從來沒有觸發過?
我寫下面的代碼沒有成功。
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();
}