Table Of Contents

Event-Driven Programming

Last Modified: February 27, 2020

Event-driven programming is a programming pattern in which you create diagram code that executes outside the dataflow structure as a result of an event occurring.

Use event-driven programming when you want diagram code to execute in response to an event. An event is anything that happens to the user interface during run time that provides a notification to other parts of a program. Events can also include external I/O, such as hardware timers or triggers that signal when acquisition completes or when an error condition occurs.

Events are handled by the Event Structure. An Event Loop, which consists of an Event Structure within a While Loop waits for events, responds to those events, then returns to waiting for the next event. Place the code that handles the event in the appropriate event case of the Event Structure.

For example, if you want an event to occur when the user presses a specific key on the panel, you can design an application to include a loop that waits until the key press event occurs, handles the event, and returns to wait for the next event. While the loop waits for the event to occur, other parts of the application can continue to run. How the application handles each event depends on the code written for that specific event. Some sections of the program may execute frequently because the events those sections handle occur frequently, and other sections of the program may not execute at all because the events never occur.

Recently Viewed Topics