[英]Timer method wont trigger when inside the method
我有一个方法叫
public void OnCaptured(CaptureResult captureResult){}
在这些方法中,我想调用计时器,我尝试启用计时器,但它根本不会触发,我还尝试创建另一个方法并在上面的方法中调用它来调用计时器滴答,但再次不起作用全部。
这是我的计时器代码:
private void TimeCountDown_Tick(object sender, EventArgs e)
{
int count = int.Parse(lblCount.Text) -1;
InvokeCD(count.ToString());
if (count < 0) {
TimeCountDown.Enabled = false;
InvokeCD("5");
}
}
您必须调用 Start() 方法才能使计时器工作。 将属性 Enabled 设置为 true 是不够的。
这必须工作:
System.Timers.Timer timer = new System.Timers.Timer(1000); //it will run every one second
public void OnCaptured(CaptureResult captureResult)
{
timer.Elapsed += TimeCountDown_Tick;
timer.Start();
}
private void TimeCountDown_Tick(object sender, System.Timers.ElapsedEventArgs e)
{
int count = int.Parse(lblCount.Text) -1;
InvokeCD(count.ToString());
if (count < 0) {
TimeCountDown.Enabled = false;
InvokeCD("5");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.