In the field of C#programming, using
to allow GUI to process messages is still a controversial topic. This obscure and dangerous function originated in the of VB6, making many developers doubt their effectiveness. Application.DoEvents()
DoEvents
Application.doevents () is safe?
Although in C#, it is strongly recommended not to use it because it is easy to cause subtle but catastrophic runtime errors. Unless developers fully understand their complex operating mechanisms and how to prevent users from entering the impact on it, it is not worthy of adventure.
Application.doevents () What exactly did?
Application.DoEvents()
In contrast to the general view,
Application.doevents () danger
is the characteristics that does not distinguish. By concession to all the news, it opened the door for a series of potential disasters. For example, when the cycle is handling diligently, the user may close the main window. Although the user interface may disappear temporarily, your code will continue to run, knowing nothing about the upcoming disaster. Application.DoEvents()
cycle is caused by the second call, and another danger will occur. This will lead to a dangerous nested cycle -level couplet, and each cycle unknowingly destroys the work of the previous cycle, leading to the chaotic situation of data damage and abnormal accidents.
Application.doevents () alternative?
Of course! Recommended methods to realize non -freezing user interface are to use threads or more modern Application.DoEvents()
and Application.DoEvents()
keywords. These technologies provide a more structured and safer method to decompose UI processing with the rest of the code, thereby avoiding traps lurking in the shadow.
The above is the detailed content of Is Application.DoEvents() Safe and Should You Use Alternatives in C#?. For more information, please follow other related articles on the PHP Chinese website!