0

I need to delay some piece of code from processing for some time in Microseconds. I tried a lots of things such as thread.Sleep(x), but it has only milliseconds resolution.

I am using .NET 2.0 in MS Visual Studio 2013.

rene
  • 41,474
  • 78
  • 114
  • 152
Filipsi
  • 69
  • 1
  • 10

1 Answers1

1
 System.Diagnostics.Stopwatch

allows you to get very small (few nanosecond) ticks, which you can convert to microseconds using this. Then you can just let an empty while loop for as long as you need.

Edit: and it even is supported by .NET 2.0.

kat0r
  • 949
  • 8
  • 17
  • 1
    You should probably use [`Thread.SpinWait()`](http://msdn.microsoft.com/en-us/library/system.threading.thread.spinwait.aspx) instead of an empty `while` loop because *"The code SpinWait executes is designed to prevent problems that can occur on computers with multiple processors"*. – Allon Guralnek Apr 15 '14 at 10:58