I have three threads: the main thread and two timers. The first timer activates the second one after a period of time and then disables itself.
I use “Thread.Sleep(int)” in order to delay the activation of the second timer. But the whole program pauses when the “Sleep” function is working.
How can I pause a thread without pausing the whole program?
Timers don’t execute your code in new threads. After their interval they raise an event in the Windows Message Queue that the main thread then executes, hence why
Thread.Sleep(int)is pausing everything.To fix this, you’ll need to actually start your own threads. It’s an easy process:
or
There are other parameters you may want to set on a thread before you start it that will affect the rest of your application such as
IsBackground