当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - What is the purpose of event listeners?

问题描述:

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 something 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#.

分享给朋友:
您可能感兴趣的文章:
随机阅读: