Event (computing)

Event (computing)

In computing an event is an action that is usually initiated outside the scope of a program and that is handled by a piece of code inside the program. Typically events are handled synchronous with the program flow, that is, the program has one or more dedicated places where events are handled. Typical sources of events include the user (who presses a key on the keyboard, in other words, through a keystroke). Another source is a hardware device such as a timer. A computer program that changes its behavior in response to events is said to be event-driven, often with the goal of being interactive.

Contents

Description

Event driven systems are typically used when there is some asynchronous external activity that needs to be handled by a program. For example, a user who presses a button on their mouse. The outside activity causes the event (it fires), some outside hardware and or software will collect data about the event, and when the program signals that it is ready to accept an event, the event will be dispatched to the event handler software that will deal with it.

A program can choose to ignore events, and there may be libraries to dispatch an event to multiple handlers that may be programmed to listen for a particular event. The data associated with an event at a minimum specifies what type of event it is, but may include other information such as when it occurred, who or what caused it to occur, and extra data provided by the event source to the handler about how the event should be processed.

Events are typically used in user interfaces, where actions in the outside world (mouse clicks, window-resizing, keyboard presses, messages from other programs, etc.) are handled by the program as a series of events. Programs written for many windowing environments consist predominantly of event handlers.

Events can also be used at instruction set level, where they complement interrupts. Compared to interrupts, events are normally handled synchronously: the program explicitly waits for an event to be serviced (typically by calling an instruction that dispatches the next event), whereas an interrupt can demand service at any time.

Delegate event model

A very common and very "programmer-friendly" variant is the delegate event model, which is provided by the most popular graphic frameworks.

Delegate event model. clickme is the event source –a button in this example–, and it contains a list of listeners.

This model is based on three entities:

  • a control, which is the event source,
  • consumers, also called listeners, that receive the events from the source,
  • interfaces (in the broader meaning of the term) that describe the protocol by which every event is to be communicated.

Furthermore, the model requires that

  • every listener must implement the interface for the event it wants to listen to
  • every listener must register with the source to declare its desire to listen to some particular event
  • every time the source generates an event, it communicates it to the registered listeners, following the protocol of the interface.

C# uses events as special delegates that can only be fired by the class that declares it. This is makes a better abstraction possible. Here's an example:[1]

class Model {
  public event Notifier notifyViews;
  public void Change() { ... notifyViews("Model"); }
}
 
class FirstView {
public View1(Model m) {
  m.notifyViews += new Notifier(this.Update1);
}
 
void Update1(string sender) {
  Console.WriteLine(sender + " was changed during update"); }
}
 
class SecondView {
public View2(Model m) {
  m.notifyViews += new Notifier(this.Update2); 
}
 
void Update2(string sender) {
  Console.WriteLine(sender + " was changed"); }
}
 
class Test {
  static void Main() {
    Model m = new Model();
 
    new FirstView(m);
    new SecondView(m);
    m.Change();}
}

Event handler

In computer programming, an event handler is an asynchronous callback subroutine that handles inputs received in a program. Each event is a piece of application-level information from the underlying framework, typically the GUI toolkit. GUI events include key presses, mouse movement, action selections, and timers expiring. On a lower level, events can represent availability of new data for reading a file or network stream. Event handlers are a central concept in event-driven programming.

The events are created by the framework based on interpreting lower-level inputs, which may be lower-level events themselves. For example, mouse movements and clicks are interpreted as menu selections. The events initially originate from actions on the operating system level, such as interrupts generated by hardware devices, software interrupt instructions, or state changes in polling. On this level, interrupt handlers and signal handlers correspond to event handlers.

Created events are first processed by an event dispatcher within the framework. It typically manages the associations between events and event handlers, and may queue event handlers or events for later processing. Event dispatchers may call event handlers directly, or wait for events to be dequeued with information about the handler to be executed.

Event notification

Event notification is a term used in conjunction with communications software for linking applications that generate small messages (the "events") to applications that monitor the associated conditions and may take actions triggered by events.

Event notification is an important feature in modern database systems (used to inform applications when conditions they are watching for have occurred), modern operating systems (used to inform applications when they should take some action, such as refreshing a window), and modern distributed systems, where the producer of an event might be on a different machine than the consumer, or consumers. Event notification platforms are normally designed so that the application producing events does not need to know which applications will consume them, or even how many applications will monitor the event stream.

It is sometimes used as a synonym for publish-subscribe, a term that relates to one class of products supporting event notification in networked settings. The virtual synchrony model is sometimes used to endow event notification systems, and publish-subscribe systems, with stronger fault-tolerance and consistency guarantees.

Examples

Mouse

With a pointing device such as a mouse, clicking a button triggers a "mouse click" event. The programmer would then program the software to respond to this "mouse click" event. Typical mouse events include mouse move and mouse button up/down.[2]

Keyboard

When a user presses a key on a keyboard, the program currently running would receive a keyboard "KeyDown" event along with relevant data such as which key the user pressed.[2]

References

  1. ^ Mössenböck, Hanspeter (2002-03-25). "Advanced C#: Variable Number of Parameters". http://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/: Institut für Systemsoftware, Johannes Kepler Universität Linz, Fachbereich Informatik. p. 26. http://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/Part2.pdf. Retrieved 2011-08-05. 
  2. ^ a b Mouse and Keyboard Events in Windows Forms. Microsoft. Retrieved on February 12, 2008.

See also

External links


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Event Stream Processing — Event Stream Processing, or ESP, is a set of technologies designed to assist the construction of event driven information systems. ESP technologies include event visualization, event databases, event driven middleware, and event processing… …   Wikipedia

  • Event-driven architecture — (EDA) is a software architecture pattern promoting the production, detection, consumption of, and reaction to events. An event can be defined as a significant change in state [K. Mani Chandy Event Driven Applications: Costs, Benefits and Design… …   Wikipedia

  • Event-driven programming — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computin …   Wikipedia

  • Event loop — In computer science, the event loop, message dispatcher, message loop, message pump, or run loop is a programming construct that waits for and dispatches events or messages in a program. It works by polling some internal or external event… …   Wikipedia

  • Event calculus — The event calculus is a logical language for representing and reasoning about actions and their effects first presented by Robert Kowalski and Marek Sergot in 1986.It was extended by Murray Shanahan and Rob Miller in the 1990s.The basic… …   Wikipedia

  • History of computing hardware — Computing hardware is a platform for information processing (block diagram) The history of computing hardware is the record of the ongoing effort to make computer hardware faster, cheaper, and capable of storing more data. Computing hardware… …   Wikipedia

  • Timeline of computing 1980–1989 — History of computing Hardware before 1960 Hardware 1960s to present Hardware in Soviet Bloc countries Artificial intelligence Computer science Operating systems Programming languages …   Wikipedia

  • Timeline of computing 1990–1999 — History of computing Hardware before 1960 Hardware 1960s to present Hardware in Soviet Bloc countries Artificial intelligence Computer science Operating systems Programming languages …   Wikipedia

  • Timeline of computing hardware 2400 BC–1949 — History of computing Hardware before 1960 Hardware 1960s to present Hardware in Soviet Bloc countries Artificial intelligence Computer science Operating systems Programming languages …   Wikipedia

  • Complex event processing — (CEP) consists of processing many events happening across all the layers of an organization, identifying the most meaningful events within the event cloud, analyzing their impact, and taking subsequent action in real time. Complex event… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”