[已解决]计时器问题 [英] [Solved] Problem in the timer

查看:116
本文介绍了[已解决]计时器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早安,
我在计时器间隔中遇到问题,
不会根据我给它的时间间隔触发timer1_Tick事件!!!

我通过向导(拖放)创建了我的计时器,并在事件timer1_Tick中写道:

Good Day,
i''m facing a problem in the timer interval,
the timer1_Tick event is not fired according to the interval i''m giving it!!!

i created my timer by wizard(drag-drop), and in the event timer1_Tick i write:

private void timer1_Tick(object sender, EventArgs e)
        {    
            Lbl_TimeLeft.Text = counter.ToString();
            counter = counter - 1;          
        }


计数器被初始化为值为100的整数.
我为间隔指定了不同的值(10或10000毫秒),但未生效,标签仍在更改相同

10x


counter is initialized as integer with value 100.
i''m giving the interval different values (10 or 10000 millisecond) but it is not effected, the label is still changing the same

10x

推荐答案

似乎您正在使用System.Windows.Forms.Timers.由于某种原因,该计时器的准确性非常差.更喜欢System.Timers.TimerSystem.Threading.Timer.

另外,请考虑使用单独的线程和System.Threading.Thread.Sleep.与计时器相比,它产生的问题要少得多.除非绝对不能避免使用计时器,否则最好使用线程.在大多数情况下,可以完全避免使用计时器.

—SA
It looks like you''re using System.Windows.Forms.Timers. By some reason, the accuracy of this timer is ridiculously poor. Prefer System.Timers.Timer or System.Threading.Timer.

Also, consider using a separate thread and System.Threading.Thread.Sleep. It creates much less problems then a timer. Prefer threading unless a timer is absolutely unavoidable. In most cases a timer can be totally avoided.

—SA


它的工作原理:)

试试这个

its working :)

try this

int counter = 100;
      
       private void button1_Click(object sender, EventArgs e)
       {
           timer1.Enabled = true;
       }

       private void timer1_Tick(object sender, EventArgs e)
       {
           label1.Text = counter.ToString();
           counter = counter - 1;
       }


这篇关于[已解决]计时器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆