C # WinForm program to deal with the background busy cause the foreground control suspended animation resolution method

Source: Internet
Author: User

This article mainly introduces the C # WinForm program to deal with the background busy caused the foreground control suspended animation solution, this article through Application.doevents () to solve this problem, and explained the role of Application.doevents (), Need friends can refer to the following

Especially in the case of loops or timer processing, when data is displayed in a form control, it can be used when there is no refresh or suspended animation due to excessive background processing.

The code is as follows:

Application.doevents ();

The role of Application.doevents ()

The code is as follows:

private void Button1_Click (object sender, EventArgs e)

{

for (int i = 0; i < 10000; i++)

{

Label1. Text = i.ToString ();

Application.doevents ();

}

}

Test a bit, no application.doevents (), the label is basically in a false panic state, the last display a 9999, plus the normal display of digital transformation.

From this test after the DoEvents function, should be doevents like the implementation of the process of synchronization. When not added, because of the priority of the problem, the program will execute the main process code, and then execute the code, and added to the later can be executed synchronously.

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.