What is the difference between an event handler and a callback function?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Generally speaking, a ‘callback’ is under the control of the detecting process.
So you tell a GUI manager “call
myactionwhen this button is pressed” and the GUI manager calls the action when the button is pressed.Event Handlers on the other hand operate at one step removed. The GUI manager is configured to send messages to an event handler. You tell an event manager that button pushes are handled by the
myactionprogram. When the button is pushed the GUI manager puts a message on the event handler’s queue and gets on with GUI managing. The event handler picks up the message from the queue, sees it’s a button push, fires up themyactionprogram, and moves on to handling the next event. Usually themyactionprogram will run as an independent thread or even a separate process.While the “event handler” pattern is more complex it is much more robust and less likely to hang when an action fails. It also makes for a more responsive GUI.