1

I need to create a while loop with 10 seconds of delay between each iteration:

while (true)
{
    // operation
    // delay for 10 seconds
}
Tobias Tengler
  • 6,848
  • 4
  • 20
  • 34

2 Answers2

6

You could use Task.Delay for this:

var timespan = TimeSpan.FromSeconds(10); 

await Task.Delay(timespan);

// or

Task.Delay(timespan).Wait();

I'm recommending this over Thread.Sleep, since Thread.Sleep blocks your entire Thread while waiting, whilst Task.Delay allows the Thread to deal with other work, while waiting.

Tobias Tengler
  • 6,848
  • 4
  • 20
  • 34
0

Just insert a sleep timer inside the while loop that sleeps for 10 seconds.

See this thread: How do I get my C# program to sleep for 50 msec?

kd2amc
  • 39
  • 8