如何知道计时器有一些价值 [英] how to know that timer has some value

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

问题描述

朋友们。



i需要知道我的计时器有什么价值。



例如计时器间隔是1000毫秒,它是enabled.i想知道当它的值是50.我做了一些工作。我可以这样做吗?



非常感谢。

hi friends.

i need to know my timer what value has.

for example timer interval is 1000ms and it is enabled.i want to know that when it's value is 50. i do some job.how can i do that?

thanks alot.

推荐答案

只有在Interval过期时才会收到通知(通过事件) - Tick事件被引发。如果你想在50ms做一些工作,那么你需要将Interval设置为50而不是1000,但你最好确保工作非常快,或者你不会跟上。如果你的意思是你有一个1000毫秒的间隔而你想每50秒做一些工作,那么这很容易:

You only get notified (via an event) when the Interval is expired - the Tick event is raised. If you want to "do some job" at 50ms then you need to set the Interval to 50, not 1000, but you had better make sure that the "job" is pretty quick, or you aren't going to keep up. If you mean that you have an Interval of 1000ms and you want to "do some job" every 50 seconds, then that's easy:
private int ticksCount = 0;
void myTimer_Tick(object sender, EventArgs e)
    {
    ticksCount++;
    if (ticksCount >= 50)
        {
        ticksCount = 0;
        DoSomeJob();
        }
    }


您无权访问此类信息。但是,您可以将间隔设置为 50 并正确处理它以达到相同的目的(例如,在 20 经过的时间。)
You have no access to such information. However you might set the interval to 50 and handle properly it to the same purpose (e.g. perform the intended 'main' task after 20 times it elapsed).


看看计时器 Interval属性,它是经过的事件 - 因为它们旨在提供您所声明的功能。
Hi, have a look at the timers Interval property and it's Elapsed event - as these were designed to provide the functionality you state you are looking for.


这篇关于如何知道计时器有一些价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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