1. Example:
using system.runtime.interopservices;[ DllImport ( kernel32.dll " )] static extern uint GetTickCount (); static void Delay (uint ms) { uint start = GetTickCount (); while (GetTickCount ()-Start < ms) { System.Windows.Forms.Application.DoEvents (); }}
2. Instructions for use:
In many cases, our program will need to wait for the previous step to complete before performing the next operation, which is most evident in the asynchronous operation or in the program that uses the message loop mechanism to communicate.
3. Application Scenario:
An example of an API:
Our own program is a, need to use the API combined with Windows Messaging mechanism, control external program B;
A to B to send a message, B to execute, at this time a need to wait for B after execution, according to the results of B, again send the next message to B
The example above is a typical time-lapse application.
When it comes to delay, you may be the first response, Sleep.
Do not talk about the accuracy of sleep delay, sleep is a fatal weakness, is the process of sleep, the process is unable to respond to external operations, into the state of suspended animation, so that a user experience is very poor, moreover, users want to stop halfway, can only wait, or force kill program.
Therefore, the sleep at this time is not advisable. What we need is a time-lapse function that can continue to respond to operations with high precision.
You can use the above example.
Reference: Suzilong11 's column C # delay function non-sleep
C # delay function non-sleep