gpt4 book ai didi

c# - 在具有 Kinect 功能的 C# 中使用计时器

转载 作者:太空宇宙 更新时间:2023-11-03 17:00:34 25 4
gpt4 key购买 nike

我正在尝试使用计时器在一定时间后生成错误框。

我目前正在使用 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 秒,消息框就会出现在屏幕上,只有那个。您必须选择“确定”,系统才能继续运行。任何低于 10 秒的内容都会被系统忽略。

请问我使用这段代码是否正确?

最佳答案

一个简单的方法是使用 2 个定时器。当一个人把目光移开时,一个计时器就会启动。另一个计时器将每隔 50 毫秒 轮询一次,以检查该人是否在看。

    //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;
}

}
}

关于c# - 在具有 Kinect 功能的 C# 中使用计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36267622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com