开发者

What is the purpose of event listeners?

开发者 https://www.devze.com 2023-01-04 05:10 出处:网络
What is the purpose of event listeners and how do I make use of them in a console application in Visual C#?

What is the purpose of event listeners and how do I make use of them in a console application in Visual C#?

Under what circumstances can I substitute them for threads, and would it be a good idea to do so?

The reason why I ask is because I would like to make use of s开发者_运维技巧omething to programmatically register button-presses on a Wiimote. Someone suggested that event listeners would be a possible way to do it. Are event listeners the right way to go about doing this?


From MSDN:

An event in C# is a way for a class to provide notifications to clients of that class when some interesting thing happens to an object. The most familiar use for events is in graphical user interfaces; typically, the classes that represent controls in the interface have events that are notified when the user does something to the control (for example, click a button).

Checkout the example in the link above.


Event listeners are methods that get executed when a certain event (for instance a keypress or a click on a button is registered). They are commonly used in GUI applications, where the standard design pattern is that one can register one or more methods with certain events provided by GUI elements (though other elements, such as Timers may also provide events).

Somebody else might know, if there are also event listeners that can be registered for console applications in C#.

0

精彩评论

暂无评论...
验证码 换一张
取 消