Event-driven programming-main loop
In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or messages from other programs/threads. Event-driven programming is the dominant paradigm used in graphical user interfaces and other applications (e.g. JavaScript web applications) that are centered on performing certain actions in response to user input. This is also true of programming for device drivers (e.g. P in USB device driver stacks[1])
In an event-driven application, there is generally a main loop that listens for events, and then triggers a callback functionwhen one of those events is detected. In embedded systems the same may be achieved using hardware interrupts instead of a constantly running main loop. Event-driven programs can be written in any programming language, although the task is easier in languages that provide high-level abstractions, such as closures.
Creating event handlers[edit]
The first step in developing an event-driven program is to write a series of subroutines, or methods, called 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 modern-day programming environments provide the programmer with event templates, allowing the programmer to focus on writing the event code.
The second step is to bind event handlers to events so that the correct function is called when the event takes place. Graphical editors combine the first 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.
The third step in developing an event-driven program is to write the main loop. This is a function that checks for the occurrence of events, and then calls the matching event handler to process it. Most event-driven programming environments already provide this main loop, so it need not be specifically provided by the application programmer. 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.
https://en.wikipedia.org/wiki/Event-driven_programming
Event-driven programming-main loop的更多相关文章
- 【转】Event Driven Programming
FROM: http://lazyfoo.net/tutorials/SDL/03_event_driven_programming/index.php Event Driven Programmin ...
- Event Driven Architecture
在微服务中使用领域事件 稍微回想一下计算机硬件的工作原理我们便不难发现,整个计算机的工作过程其实就是一个对事件的处理过程.当你点击鼠标.敲击键盘或者插上U盘时,计算机便以中断的形式处理各种外部事件 ...
- [转]Table-Driven and Data Driven Programming
What is Table-Driven and Data-Driven Programming? Data/Table-Driven programming is the technique of ...
- tensorflow_目标识别object_detection_api,RuntimeError: main thread is not in main loop,fig = plt.figure(frameon=False)_tkinter.TclError: no display name and no $DISPLAY environment variable
最近在使用目标识别api,但是报错了: File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/script_o ...
- event driven的一些概念
1. event :Something that happens during your application that requires a response. 2.event object:Th ...
- event driven model
http://www.jdon.com/eda.html http://blog.csdn.net/gykimo/article/details/9182287 事件代表过去发生的事件,事件既是技术架 ...
- 理解Nodejs的Event Loop
Node的“event loop”主要是用来处理高输出量的.这很神奇,这也是为什么node可以在单线程的情况下同时处理很多的后台操作.本文就会集中讲述event loop是怎么运行的,这样你可以可以使 ...
- 【转】Beginning Game Programming v2.0
Beginning Game Programming v2.0 Last Updated 8/19/18 Greetings everyone, welcome to the ground up re ...
- Spring 4 + Reactor Integration Example--转
原文地址:http://www.concretepage.com/spring-4/spring-4-reactor-integration-example Reactor is a framewor ...
- SDL2.0教程翻译·目录
原文地址:SDL 2.0 Tutorial Index Welcome! 下面的教程旨在为你提供一个SDL2.0以及c++中游戏设计和相关概念的介绍.在本教程中,我们假定你对C++有一定程度上的知识, ...
随机推荐
- Drop it FreeCodeCamp
function drop(arr, func) { // Drop them elements. for(var start=0 ;start<arr.length; start++){ if ...
- JS 输名字随机弹出
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- day28 re(正则)模块
目录 re模块有什么用? re模块的基础使用 元字符 终极 贪婪模式 非贪婪模式 re模块高级 comple match和search re.split() sub和subn 分组 re模块有什么用? ...
- jmeter录制
1.添加线程组 2.添加HTTP代理服务 3.浏览器的代理设置 4.添加证书 5.排除模式 .*\.(jpg|css|png|git).*或者 .*\.jpg 6.录制只限制某一个ip段 7.最后一句 ...
- NTP学习路线
NTP了解路线 基础 ntp配置中的tinker参数? ntp的同步方式slew step的区别? restrict含义?restrict -6 default ignore含义? fudge 127 ...
- web前端知识框架
- BZOJ 3674 可持久化并查集加强版(按秩合并版本)
/* bzoj 3674: 可持久化并查集加强版 http://www.lydsy.com/JudgeOnline/problem.php?id=3674 用可持久化线段树维护可持久化数组从而实现可持 ...
- HTTP中的重定向和请求转发的区别(转)
时间长有些忘了,转篇文章加深一下印象: 一.调用方式 我们知道,在servlet中调用转发.重定向的语句如下:request.getRequestDispatcher("new.jsp&qu ...
- [asp.net]ashx中session存入,aspx为null的原因(使用flash uploader)
I am using uploadify to upload files, they automatically post to the handler. I then modify the sess ...
- 使用从mysql中取数据
import MySQLdb conn=MySQLdb.connect(host="xx",user="xx",passwd="xx",db ...