事件侦听器如何工作?

编程入门 行业动态 更新时间:2024-10-24 08:26:12
本文介绍了事件侦听器如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

他们是否反复检查条件并执行是否满足条件.例如,操作系统如何确切知道何时插入USB设备,或者MSN如何确切知道何时收到电子邮件.如何运作?

Do they repeatedly check for the condition and execute if the condition is met. Ex, how the OS knows exactly when a USB device is plugged in, or how MSN knows exactly when you get an email. How does this work?

谢谢

推荐答案

在底层,操作系统内核会知道"发生什么事情,因为相关设备向CPU发送了硬件中断.

At the low level, the OS kernel "knows" when something happens, because the device in question sends the CPU a hardware interrupt.

因此,例如当网络数据包到达时,网络控制器将发送一个中断,并且OS内核将做出适当的响应.

So when, say a network packet arrives, the network controller sends an interrupt, and the OS kernel responds as appropriate.

在程序级别,它的工作方式大不相同-大多数应用程序运行一个事件循环",从中获取一条消息(例如,操作系统发出的一条消息,指出在应用程序的这一点上单击了鼠标" ),对此进行相应的操作,然后侦听更多消息.如果没有消息,则操作系统将休眠线程,直到有消息要传递为止.

At the program level, it works quite differently - most application programs run an "event loop", where they fetch a message (say, a message from the OS saying that "the mouse was clicked on this point in your application"), perform the appropriate actions in response to that, and then, listen for more messages. If there is no message, the OS sleeps the thread until it has a message to deliver.

更多推荐

事件侦听器如何工作?

本文发布于:2023-11-23 03:26:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619907.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:侦听器   事件   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!