I have this code :
void Main()
{
System.Timers.Timer t = new System.Timers.Timer (1000);
t.Enabled=true;
t.Elapsed+= (sender, args) =>c();
Console.ReadLine();
}
int h=0;
public void c()
{
h++;
new Thread(() => doWork(h)).Start();
}
public void doWork(int h)
{
Thread.Sleep(3000);
h.Dump();
}
I wanted to see what happens if the interval is 1000 ms and the job process is 3000 ms.
However I saw a strange behavior –
the 3000 ms delay occurs only at the start !
How can I make each doWork sleep 3000 ms?
As you can see here, at the beginning there is a 3 second delay, and then it iterates 1 second each.

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)intoc().What you have currently is:
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 awhileloop with aSleep()in it. Simple, and doesn’t involve lots of threads.