I am porting part of firmware to a gui written in c#. I found out that
nop()
is a function that actually does nothing and delays the execution by some number of clock cycles.
Lets say if I use nop() it will delay the execution in firmware by two milliseconds. How do I delay things in c#?
Thanks in advance,
System.Threading.Thread.Sleep(milliseconds);
Note that blocking your GUI's main thread for more than a few milliseconds is generally a bad idea. It may be better to use a timer that wakes up after a few milliseconds, to allow event-handling to happen in the meantime. Also, if you want to pause before doing some I/O, consider using asynchronous I/O instead.
Also note that neither Windows or .NET provide any real-time guarantees. A call to Thread.Sleep(2)
will pause for at least 2 milliseconds, but that thread may not resume execution for many milliseconds beyond that.