在具有Kinect功能的c#中使用计时器
我试图使用计时器在一定时间后生成一个错误框 我目前正在使用Kinect和face属性 这就是我到目前为止所做的:在具有Kinect功能的c#中使用计时器,c#,timer,C#,Timer,我试图使用计时器在一定时间后生成一个错误框 我目前正在使用Kinect和face属性 这就是我到目前为止所做的: LookingAwayResult.Text = frameResult.FaceProperties[FaceProperty.LookingAway].ToString(); Check = frameResult.FaceProperties[FaceProperty.LookingAway].ToString(); int TimeDelay = 5000; if (Ch
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秒,消息框就会出现在屏幕上,就是那个。您必须选择“确定”,系统才能再次运行。任何低于10秒的情况下,系统都会忽略这一点
请问我的代码是否正确?一个简单的方法是使用两个计时器。当一个人看向别处时,一个计时器将启动。另一个计时器将轮询ever
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;
}
}
}
一个简单的方法是使用2个计时器。当一个人看向别处时,一个计时器将启动。另一个计时器将轮询ever
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;
}
}
}
OP对于计时器来说是新的,您的示例使用LINQ?OP对于计时器来说是新的,您的示例使用LINQ?