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.