Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top