What exactly does the Application.Doevents() method do?

Asked

Viewed 1,477 times

4

According to the help of Microsoft, the method Application.Doevents():

Processes all Windows messages that are currently in the message queue.

But what does that mean?

Why does he say messages? What line is this?

  • 1

    You can add the tag [tag:winforms] if your question is limited to this library. It exists in WPF There are better alternatives for it.

1 answer

3


Message is a term that Windows uses. When you program for Windows you kind of are using a framework from it, then the application stays the whole time communicating with the operating system through messages. It’s easy to send messages to him when you want, but to receive you need to subscribe to pool of events and it will call its function whenever it has a message its application. It’s like the events system of C#, but a little lower-level, basically a function of callback and a huge switch to decide what to do according to the received message.

This method reads those messages. I’m not sure, but it’s possible to do it with internal Windows Forms messages that aren’t coming from Windows. This may be necessary to "unlock" the loop events in single application thread. Its use simplifies the application by maintaining a certain responsiveness (in the correct sense of the word, not as they use on the web) of the UI.

In most applications its use is not necessary and today when you have something that can treat the execution is recommended the use of asynchronicity. If you don’t know how to use it right, and it’s hard, you can create complicated for the application. There were times that had more utility for lack of better option, so many old articles on the subject may have their expiration date.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.