Reputation: 63
How can I set my timer to work with seconds? When I use the timer from toolbox, without any changes it starts working with another time unit.
I will be grateful for any help which you can give me.
I have something like this:
t = 0;
timer1.Start();
if (t == 600)
timer1.Stop();
Upvotes: 2
Views: 2645
Reputation: 3439
Timer.Interval property takes the value in milliseconds. You should multiply your valued to 1000 to set the interval to seconds.
aTimer.Interval = 1*1000; // 1 second interval
aTimer.Interval = 2*1000; // 2 seconds interval
Edit:
If I understood correctly, you should register Timer.Tick event like
aTimer.Tick += new EventHandler(TimerEventProcessor);
and check the value of t
in its event handler. If t == 600
then you can stop the timer
private static void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
{
...
t++;
if(t == 600)
aTimer.Stop();
}
Upvotes: 3
Reputation: 3248
The timer uses milliseconds as unit of time, you can do computation to fit your needs. In this case you want to delay in seconds, you can do something like:
int secondsInterval = 5;
timer.Interval = secondsInterval * 1000;
Hope this helps.
Upvotes: 1
Reputation: 327
EDIT
Use timer.interval = 1000 * n;
where n is the number of seconds between the ticks.
Upvotes: 3
Reputation: 8166
multiply the number of seconds you wish by 1000, it uses milliseconds out of the box
Upvotes: 2