Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have two timers
timer1 is slow , tick time of 1 min
while timer2 needs to be extremely fast , tick time of 10 milliseconds

each have separate tick time

now in i have created a button to stop all working and it should also stop timer from working

but as timer1 tick time is 1 min , i have to wait until 1 min till timer really stops

also the problem is some times code in timer2 tick event can not be complete in 10 milliseconds so whole event is overlapping . it's fine overlapping in working but if i press stop button then all overlapped timer events also must be stopped

how to do this ?
Posted
Comments
Shahan Ayyub 11-May-13 7:21am    
Have you used "Timer.Enabled" property to stop timer ?
Marco Bertschi 11-May-13 8:09am    
Proper way to do it, nice.
But IMO Timer.Stop() [http://msdn.microsoft.com/en-us/library/system.timers.timer.stop.aspx] would suit better.
Shahan Ayyub 11-May-13 15:47pm    
Can you please share your code with us ? I am still not clear that if you are already using these guidelines and having some trouble using them or the below guidelines resolves this thread.

timer1.stop
timer2.stop

This should do it. If you're still getting one last timer event firing after that, then try setting a public boolean to false in your button, and then check for it in the beginning of your timer events. If it's false (or whatever you set it to look for), then exit the timer event.

- Pete
 
Share this answer
 
v2
Hi,

AFAIK you can directly stop a timer using Timer.Stop[^].
Of course, this solution supposes that you have direct access to your timer object from the button code.
But even when you have to wait 1 min, what is the problem?
The timer ain't does nothing until the tick event comes up.


cheers,
Marco
 
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