re-enable the Timer

sweit

Member
Joined
Mar 30, 2016
Messages
9
Programming Experience
10+
Hello,

I have a timer on my form. When I press a button the on the form the timer starts. In the Timer.tick event handler I disable the timer (Timer.Enable = False). I'm trying to re-enable the timer in my code. I know the program gets to the timer.enabled = true statement but the Timer.Tick event never happens again. What am I doing wrong.

Thank you,
Steve
 
If you enable the Timer then it will raise its Tick event. That's a fact. If what you're doing is not working as you expect then, unless your system is broken in some way, you did something wrong. As you have not shown us what you did, we have no hope of determining what's wrong with it.
 
I used a system.timer instead of the form timer control and everything works as expected.

If that's the case then the issue was that you were doing other work on the UI thread so the Tick event of the Timer, which would have been raised, could never be handled. The Timers.Timer raises its Elapsed event on a secondary thread so you have probably now moved that work to that secondary thread. That's good because you should never be doing long-running work on the UI thread to begin with.

Just be aware though, that you cannot safely modify the UI from a secondary thread. If you want to update the UI from within that work then you should make sure to marshal a call back to the UI thread to do so.
 
Back
Top