Recently made a personal digital library management system, because the computer files involved in the scan, want to do a real-time display of the current sweep file function, similar to the 360 file scanning effect, originally intended to use multi-threaded to achieve, but the method is too many did not realize, and later in the program control, due to too many files, There is a phenomenon of suspended animation, even their own defined timer timer has been suspended animation, so this problem must be resolved, and then the process of the present, suddenly found Application.doevents (), the use of a bit, love is very good, solve their own problems encountered. This paper mainly introduces the Application.doevents () method.
Remember the first time to use Application.doevents () is to load a large amount of data can have a data loading hint, not the system appears suspended animation phenomenon, then did not go deep to study his principle is how, The results have been used in many places application.doevents (), today saw some of the articles on this, know that I used to be inappropriate, some places need to be cautious with application.doevents ().
First of all, we look at the larger cycle of the program, its role is good, a real-time response to the effect, such as:
for (int q = 0; q < 1000000; q++)
{
TextBox1.Text = Q.tostring ();
Application.doevents ();//real-time response to values in text boxes
}
If not added DoEvents, because the cycle time will be longer than the state of suspended animation, and the program can not handle other events. And if add DoEvents words will be the value of the text box in real-time response to the user to bring a better user experience, but DoEvents also brought about the efficiency of the problem, processing the same event called the DoEvents after the efficiency of several times, which is why the use of caution.
Use of application.doevents ()