Every time the timer ticks, you start a thread to do some sleeping; that thread is completely isolated, and the timer is going to keep on firing every second. Actually, the timer fires every second even if you move the Sleep(3000)
into c()
.
What you have currently is:
1000 tick (start thread A)
2000 tick (start thread B)
3000 tick (start thread C)
4000 tick (start thread D, A prints line)
5000 tick (start thread E, B prints line)
6000 tick (start thread F, C prints line)
7000 tick (start thread G, D prints line)
8000 tick (start thread H, E prints line)
...
It is unclear what you are trying to do. You could disable the timer when you don’t want it firing, and resume it again once ready, but it is unclear what the purpose of the Sleep()
is here. Another option is just a while
loop with a Sleep()
in it. Simple, and doesn’t involve lots of threads.