C # inclusive Delay function non-sleep

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.