Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Event loop  



1.1  Event handlers  







2 Common uses  





3 Interrupt and exception handling  





4 See also  





5 References  





6 External links  














Event-driven programming






Català
Ελληνικά
Español
Euskara
فارسی
Français
Galego

Hrvatski
Bahasa Indonesia
Italiano
עברית
Magyar

Português
Română
Русский
Simple English
Српски / srpski
Suomi
Türkçe
Українська
Tiếng Vit


 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

(Redirected from Event-based programming)

Incomputer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by external events. Typical event can be UI events from mice, keyboards, touchpads and touchscreens, or external sensor inputs, or be programmatically generated (message passing) from other programs or threads, or network events.

Event-driven programming is the dominant paradigm used in graphical user interfaces applications and network servers.

In an event-driven application, there is generally an event loop that listens for events and then triggers a callback function when one of those events is detected.

Event-driven programs can be written in any programming language, although the task is easier in languages that provide high-level abstractions.

Although they do not exactly fit the event-driven model, interrupt handling and exception handling have many similarities.

It's important to differentiate between event-driven and message-driven (aka queue driven) paradigms: Event-driven services (e.g. AWS SNS) are decoupled from their consumers. Whereas queue / message driven services (e.g. AWS SQS) are coupled with their consumers.[1]

Event loop[edit]

Because the event loop of retrieving/dispatching of events are common amongst applications, many programming frameworks take care of their implementation and expect the user to provide only the code for the event handlers.

RPG, an early programming language from IBM, whose 1960s design concept was similar to event-driven programming discussed above, provided a built-in main I/O loop (known as the "program cycle") where the calculations responded in accordance to 'indicators' (flags) that were set earlier in the cycle.

Event handlers[edit]

The actual logic is contained in event-handler routines. These routines handle the events to which the main program will respond. For example, a single left-button mouse-click on a command button in a GUI program may trigger a routine that will open another window, save data to a database or exit the application. Many IDEs provide the programmer with GUI event templates, allowing the programmer to focus on writing the event code.

While keeping track of history is normally trivial in a sequential program. Because event handlers execute in response to external events, correctly structuring the handlers to work when called in any order can require special attention and planning in an event-driven program.

In addition to writing the event handlers, event handlers also need to be bound to events so that the correct function is called when the event takes place. For UI events, many IDEs combine the two steps: double-click on a button, and the editor creates an (empty) event handler associated with the user clicking the button and opens a text window so you can edit the event handler.

Common uses[edit]

Most existing GUI architectures use event-driven programming.[2] Windows has an event loop. The Java AWT framework processes all UI changes on a single thread, called the Event dispatching thread. Similarly, all UI updates in the Java framework JavaFX occur on the JavaFX Application Thread.[3]

Most network servers and frameworks such as Node.js are also event-driven.[4]

Interrupt and exception handling[edit]

See also[edit]

References[edit]

  1. ^ Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022). Domain-Driven Design with Java - A Practitioner's Guide. Packt Publishing. ISBN 9781800564763.
  • ^ Samek, Miro (April 1, 2013). "Who Moved My State?". Dr. Dobb's. Retrieved 2018-01-28.
  • ^ Fedortsova, Irina (June 2012). "Concurrency in JavaFX". JavaFX Documentation Home. Oracle. Retrieved 4 January 2018. The JavaFX scene graph, which represents the graphical user interface of a JavaFX application, is not thread-safe and can only be accessed and modified from the UI thread also known as the JavaFX Application thread.
  • ^ Event-Driven Programming in Node.js.
  • External links[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Event-driven_programming&oldid=1232167798"

    Categories: 
    Programming paradigms
    Events (computing)
    Hidden categories: 
    Articles with short description
    Short description is different from Wikidata
    Articles to be expanded from May 2024
    All articles to be expanded
    Articles with empty sections from May 2024
    All articles with empty sections
    Articles using small message boxes
    Webarchive template wayback links
    Articles with example pseudocode
     



    This page was last edited on 2 July 2024, at 09:22 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki