In the C # window program, if sleep is called in the main thread, the interface renders suspended animation before sleep finishes, and cannot respond to any action!
The following implementation of the non-exclusive delay function, the delay is outdated in the interface can still respond to messages:
Public Static void Delay (int millisecond) { int start = environment.tickcount; while (Math.Abs (Environment.tickcount-start) < millisecond) { application.doevents (); }}
About Math.Abs ():
Environment.tickcount, the internal API is implemented with the DWORD GetTickCount (), which derives the value of the property from the system timer and stores it as a 32-bit signed integer. Therefore, if the system is running continuously, the TickCount will increment from zero to Int32 within about 24.9 days. MaxValue, and then jump to Int32. MinValue (This is a negative number), and then increments to 0 over the next 24.9 days. The DWORD is unsigned, and the value returned by the Environment.tickcount property is signed, so half of the value is represented by a negative number!
C # inclusive Delay function non-sleep