views:

68

answers:

3

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?

+1  A: 

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

inflagranti
+2  A: 

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.

KMan
A: 

Take a look at this event tutorial to understand what is an 'event listner' : Events Tutorial

Patrice Pezillier
I already took a look at this and could not make much sense of it. Please bear in mind that I am a student with not much in way of programming experience.
Omar