Click here to Skip to main content
15,911,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted

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:
C#
private int ticksCount = 0;
void myTimer_Tick(object sender, EventArgs e)
    {
    ticksCount++;
    if (ticksCount >= 50)
        {
        ticksCount = 0;
        DoSomeJob();
        }
    }
 
Share this answer
 
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).
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900