2016-03-28 10 views
2

タイマーを使用して一定時間後にエラーボックスを生成しようとしています。Kinect機能を使用したC#でのタイマーの使用

私は現在Kinectと顔のプロパティを使用しています。

これは私がこれまで持っているものです。

LookingAwayResult.Text = frameResult.FaceProperties[FaceProperty.LookingAway].ToString(); 

Check = frameResult.FaceProperties[FaceProperty.LookingAway].ToString(); 

int TimeDelay = 5000; 
if (Check == "Yes") 
{ 
    Thread.Sleep(TimeDelay); 

    MessageBox.Show("Looking is set to Yes", "Looking Error", 
     MessageBoxButton.OK, MessageBoxImage.Exclamation 
    ); 
    LookingAwayResult.Text = Check; 
} 

私はできるだけ早く私が離れて見えるよう、メッセージボックスがちょうどシステムをスパム続けるので、それは権利だとは思いません。これは私が何である

本当に後:

はできるだけ早く人が離れて見えるように、私はタイマーを開始するので、彼らが離れて10秒以上見た場合、メッセージボックスが画面に表示されていることを、ただ一つ。そして、システムが再び稼働し続けるためには、「OK」を選択する必要があります。 10秒未満であれば、システムはこれを無視します。

私はこのコードで正しい行にしてください。

答えて

-1

これを行う簡単な方法は、2つのタイマーを使用することです。 1人のタイマーは、人が目を離すと開始します。他のタイマーは、その人が探しているかどうかを確認するために、常に50msをポーリングします。

//initilize look away timer for 10 seconds 
    Timer lookAwayTimer = new Timer(interval: 10000); 

    //inialize the poll tiomer for 50 ms 
    Timer pollTimer = new Timer(interval: 50); 
    public ClassConstructor() 
    { 
     //if 10 seconds expires then show message box 
     lookAwayTimer.Elapsed += (s, e) => 
     { 
      MessageBox.Show("Looking is set to yes", "Looking Error", MessageBoxButton.OK); 
     }; 

     //enable poll timer 
     pollTimer.Enabled = true; 

     //check if person is looking. if they are then enable the lookAwayTimer. If they stop looking 
     //then disable the timer 
     pollTimer.Elapsed+=(s,e)=> 
     { 
      LookingAwayResult.Text = frameResult.FaceProperties[FaceProperty.LookingAway].ToString(); 

      Check = frameResult.FaceProperties[FaceProperty.LookingAway].ToString(); 

      if(Check=="Yes") 
      { 
       lookAwayTimer.Enabled = true; 
      } 
      else 
      { 
       lookAwayTimer.Enabled = false; 
      } 

     } 
    } 
+0

OPはタイマーには新しく、例ではLINQを使用していますか? – Snoopy