private static void Main(string[] args)
{
for (;;)
{
TemporaryCityTool.TemporaryCityTool.AddCity();
Console.WriteLine("waiting...");
Thread.Sleep(3600);
}
}
why Thread.sleep
not working. I am getting message waiting all the time. I want that application will wait 10 minutes then continue again.
Thread.Sleep
takes a value in milliseconds, not seconds, so this only tells the current thread to wait 3.6 seconds. If you want to wait 10 minutes, use:
Thread.Sleep(1000 * 60 * 10); // 600,000 ms = 600 sec = 10 min
This is probably an inappropriate use of Sleep
, though. Consider using a Timer instead, so that you get something along the lines of:
// Fire SomeAction() every 10 minutes.
Timer timer = new Timer(o => SomeAction(), null, 10 * 60 * 1000, -1);
See this StackOverflow thread for more details on that.
The argument of the Sleep method is in milliseconds, so if you want to sleep for 10 minutes:
Thread.Sleep(10 * 60 * 1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With