Skip to main content
Added explanation
Source Link
Tobias Tengler
  • 7.5k
  • 4
  • 26
  • 35

You could use Task.Delay for this:

var millisecondstimespan = TimeSpan.FromSeconds(10 * 1000;); await Task.Delay(millisecondstimespan); // or Task.Delay(millisecondstimespan).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.

You could use Task.Delay for this:

var milliseconds = 10 * 1000; await Task.Delay(milliseconds); // or Task.Delay(milliseconds).Wait(); 

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.

Source Link
Tobias Tengler
  • 7.5k
  • 4
  • 26
  • 35

You could use Task.Delay for this:

var milliseconds = 10 * 1000; await Task.Delay(milliseconds); // or Task.Delay(milliseconds).Wait();