ฉันมีวิธีการที่ส่งคืนค่าบูล แต่ควรรอโดยส่งคืนค่าจนกว่า System.Timers.Timer จะเพิ่มเหตุการณ์ที่ผ่านไป เนื่องจากค่าที่ฉันต้องการส่งคืนถูกตั้งค่าในเหตุการณ์ที่ผ่านไปของตัวจับเวลา
public static bool RecognizePushGesture()
{
List<Point3D> shoulderPoints = new List<Point3D>();
List<Point3D> handPoints = new List<Point3D>();
shoulderPoints.Add(Mouse.shoulderPoint);
handPoints.Add(Mouse.GetSmoothPoint());
Timer dt = new Timer(1000);
bool click = false;
dt.Elapsed += (o, s) =>
{
shoulderPoints.Add(Mouse.shoulderPoint);
handPoints.Add(Mouse.GetSmoothPoint());
double i = shoulderPoints[0].Z - handPoints[0].Z;
double j = shoulderPoints[1].Z - handPoints[1].Z;
double k = j - i;
if (k >= 0.04)
{
click = true;
dt.Stop();
}
};
dt.Start();
//should wait with returning the value until timer raises elapsed event
return click;
}
ขอบคุณทิม
RecognizePushGesture
รับมอบสิทธิ์เป็นพารามิเตอร์ ซึ่งจะทำงานเป็นการโทรกลับทุกครั้งที่k >= 0.04
- person ebb   schedule 23.10.2012