我正在使用Kinect,每隔一段時間它都會關閉中間程序,導致各種錯誤。由於這個問題沒有修復,我想設置我的程序暫停,只要Kinect做到這一點。等待攝像頭重新連接C#
public ManikinTrackingManager()
{
KinectSensor.GetDefault().IsAvailableChanged += MainWindow_IsAvailableChanged;
}
private bool kinnected = true;
private void MainWindow_IsAvailableChanged(object sender, IsAvailableChangedEventArgs e)
{
if (e.IsAvailable == true)
{
SpeechSynthManager.SpeakAsync("Kinect has been found!");
kinnected = true;
}
else
{
SpeechSynthManager.SpeakAsync("Your Kinect has been disconnected!");
SpeechSynthManager.SpeakAsync("Please wait while I try to fix this problem!");
kinnected = false;
waitForReconnect();
}
SpeechSynthManager.SpeakAsync("CHANGED " + e.IsAvailable.ToString());
}
這是我必須斷開連接。但是,如果我嘗試使用一個計時器上一個循環等待,直到相機重新連接,說
void waitForReconnect()
{
while (kinnected == false)
{
Thread.sleep(500);
}
}
然而,而不是暫停,直到Kinect的重新連接,這段代碼只是凍結了我的整個計算機。我還應該嘗試什麼?
IsAvailable'是否重新連接失敗'IsAvailableChanged'爲真? – stuartd
它應該,但我不確定是否重新連接觸發器IsAvailableChanged @stuartd – Flotolk
@Flotolk,SpeakAsync'返回'Task'嗎? – Nkosi